r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3-OLD1]

Oldes
9-Feb-2009
[10812]
>> b: make list! 10001 tm 100 [clear head b repeat i 10000 [b: insert 
b i]]
0:00:00.25
== 0:00:00.25

>> b: make block! 10001 tm 100 [clear head b repeat i 10000 [b: insert 
b i]]
0:00:00.25
== 0:00:00.25
Steeve
9-Feb-2009
[10813]
Oldes, you do appends not insertion
Oldes
9-Feb-2009
[10814x2]
Anyway.. list! and hash! are no longer in R3
I see.. interesting.

>> b: make list! 10001 tm 100 [clear head b repeat i 10000 [insert 
b i]]
0:00:00.203
== 0:00:00.203

>> b: make block! 10001 tm 100 [clear head b repeat i 10000 [insert 
b i]]
0:00:13.031
== 0:00:13.031
[unknown: 5]
9-Feb-2009
[10816x2]
I don't know much about vector or map but I hope that we haven't 
loss the functionality of list and hash in R3.
Or at least have something better.
Henrik
9-Feb-2009
[10818]
I used list! once in list-view, but found that it had too much overhead, 
when needing to use it as a block, so it had to be converted.
[unknown: 5]
9-Feb-2009
[10819x2]
Yeah that is what made list less desirable for me as well  Henrik.
Should to-block work on vector!?
Oldes
9-Feb-2009
[10821]
I think so.
[unknown: 5]
9-Feb-2009
[10822x2]
>> c: make vector! [32 100]
== vector!

>> c/1
== 0

>> c/1: 100000
== 100000

>> c/2: 200000
== 200000

>> c/1
== 100000

>> c/2
== 200000

>> to-block c
== [vector!]
the last piece seems abnormal to me.
Oldes
9-Feb-2009
[10824]
I don't think is't ready already. Also map! still has some issues.
BrianH
9-Feb-2009
[10825x3]
Map! has issues for now (see CureCode), and the traversal thing is 
being worked on. Vector! is almost completely nonfunctional now.
There are plans to extend FOREACH to map! and object!, and MAP could 
make sense too I suppose, but no plans for that. What did you use 
hash! for that wasn't keyed search, Doc, and what advantages did 
it give you over block! aside from a different datatype?
Also, don't forget user-defined datatypes. We are only including 
the most useful datatypes by default - you will be able to add your 
own later once we have user-defined datatypes.
Dockimbel
9-Feb-2009
[10828]
Multiple keys pointing on the same data (I'm using traversal to locate 
the value once the key is found). I guess that using map!, it would 
require to duplicate the value for each key?
BrianH
9-Feb-2009
[10829]
No, just duplicate *references* to the same value.
Pavel
9-Feb-2009
[10830]
Paul if I understand documentation Vector must be one type (homogenous) 
ie good for file pointer, bad for records (multiple type)
BrianH
9-Feb-2009
[10831]
It only becomes duplicate values if the value is not a reference 
type (numbers, characters, etc.).
Dockimbel
9-Feb-2009
[10832]
Brian: Good to know.
BrianH
9-Feb-2009
[10833]
Pavel, yes, the homogenous type is the only main difference relative 
to blocks. Only use vectors if you need that, else use blocks.
Dockimbel
9-Feb-2009
[10834]
So, if I understand correctly, map! offers a superset of hash! features 
(without giving up anything)?
Pavel
9-Feb-2009
[10835]
Not bad if the performance would be good (especially for quite large 
pointer table to database file), save in size was already mentioned
BrianH
9-Feb-2009
[10836x2]
You give up position and persistent ordering, and in theory you also 
give up duplicate keys though there is a bug ticket about that.
You also have to conform to the key/value pattern. Map! is more comparable 
to object! nowadays.
Pavel
9-Feb-2009
[10838]
Doc question arise when large insert into large table comes, in hash 
inserting is the slower the bigger is table (maybe even nonlinear)
BrianH
9-Feb-2009
[10839x2]
It can be key/[block of values] though.
We are extending support of many of the functions that people traditionally 
associated with series to objects and maps, without making them into 
series. So that means that APPEND works, but INSERT doesn't because 
of the position stuff.
Pavel
9-Feb-2009
[10841]
For Map also limit about 500000 items was mentioned, it suggest an 
idea use Map in pagged manner. Ie for larger set use multiple Maps 
rather fixed size in the manner of cache.
Dockimbel
9-Feb-2009
[10842]
Pavel: is map! any better in that case?
Pavel
9-Feb-2009
[10843]
I have no exact comparison all mentioned is only ideas
BrianH
9-Feb-2009
[10844]
SELECT works on object! and map! but FIND doesn't. PICK and POKE 
work, but they take keys rather than indexes. There are some (at 
this point undocumented) limits on what can be used as keys too (at 
least you can't use a block as a key in practice), but that may be 
a bug.
Dockimbel
9-Feb-2009
[10845]
Lot of new exceptions to remember...
Pavel
9-Feb-2009
[10846]
Brian Block as key would be good for reversed index IMO. Question 
if it would be usefull.
BrianH
9-Feb-2009
[10847]
Well, in some cases to fix, but yes, lots of exceptions. The guideline 
is that maps and objects don't have position, but series do. So the 
position-dependent functions don't work but their non-position-dependent 
counterparts do. Ports don't work like series either, so there is 
another whole set of differences to remember.
Dockimbel
9-Feb-2009
[10848]
Good point Pavel, how does map! handle the key/key case? (being able 
to exchange the role of key<=>value). Would it require to use two 
map! to being able to do fast lookups in both cases? So n-tuple stored 
=> n map! value to hash everything?
BrianH
9-Feb-2009
[10849x2]
Pavel, the problem is that we can't hash complex structures (for 
now) so there is no advantage to using them as keys. I want a keys-of 
function though that returns a block of the keys that reference a 
value (by same? semantics for the value, perhaps).
The words-of function already returns *all* of the keys of a map!, 
just like it does for objects.
Pavel
9-Feb-2009
[10851]
I dont want to use keys in this way (difficult keys) the opposite 
is true, keys should be simplest possible.
BrianH
9-Feb-2009
[10852]
Well then you have no problem then :)
Pavel
9-Feb-2009
[10853x3]
Doc I think so
But it is not necessary week point if the design of data would be 
good
Anyway it leads to multiple lookup when data is difficult
BrianH
9-Feb-2009
[10856x2]
I agree, Doc, that sounds like a good plan. Map! storage and implementation 
is in theory more efficient than hash!, so having two of them shouldn't 
be a problem, as long as your wrapper functions keep track of the 
mirroring.
The only trick is that you remember that none means nothing, so don't 
bother with a none key. The theory of map! is either:

- Keys that are associated with none don't exist in the map!, so 
assigning none to a key makes it go away.

- All possible keys are in the map! but only the ones associated 
with something other than none are displayed.

There is no difference between these two theories in practice, and 
whether there is memory allocated for keys that you can't see is 
an implementation detail that is irrelevant to the use of map! (though 
there is usually not).
Steeve
9-Feb-2009
[10858]
something related, in the past i made some tests to simulate hashs 
with integer keys in R2. I used a bitset as an index, mixed with 
block of blocks to store data.

my tests show that for 10000 records,  finding data is near as fast 
as with hashs. 
actually it's incomplete but you have the idea with this:

REBOL []
f: fast-dic: context [
	size: 100000

 hash: 128 - 1	;** hash size speed up the search, must be a power 
 of 2 - 1 (ie. 15, 31, 63, 127, 257 ...)
	master: copy/deep head insert/dup/only [] [] hash + 1
	index: make bitset! size
	flag: func [idx [integer!]][
		unless find index idx [
			insert index idx

   insert/only insert tail pick master idx and hash + 1 idx copy []
		]
	]
	flag?: func [idx [integer!]][find index idx]
	deflag: func [idx [integer!]][
		remove/part index idx
		remove/part find pick master idx and hash + 1 idx 2
	]
] 

t: now/time/precise
loop 10000 bind [flag random 99999] f
print now/time/precise - t
t: now/time/precise
loop 10000 bind [flag? random 99999] f
print now/time/precise - t
GiuseppeC
9-Feb-2009
[10859]
Just a question. Is there a way to rappresent  Unicode Characters 
inside a string with an escape sequence ?
BrianH
9-Feb-2009
[10860x2]
^(hex characters)

. The console may not render the character properly if the font doesn't 
support it though - it may look like a space.
Same as R2, but you can provide more hex characters.