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

World: r3wp

[Core] Discuss core issues

Terry
7-May-2010
[16460]
(probably an R3 question)
Maxim
7-May-2010
[16461x2]
>> probe a
make map! [
    r 4
]
== make map! [
    r 4
]

>> foreach [key value] a [print key]
r
>> a/e: 5
== 5

>> foreach [key value] a [print key]
r
e
I just tried the most obvious and it worked.
Steeve
7-May-2010
[16463]
>>foreach key a [print key]
works too.
Terry
7-May-2010
[16464]
how about this.. adding a variable as key in a map ie:
n: make map![]
b: 4398

n/b: "42" ; where b is 4398?
Steeve
7-May-2010
[16465x3]
n/:b:
n/:b:
n/:b:
Terry
7-May-2010
[16468]
ah ;)
Steeve
7-May-2010
[16469]
oups...
Terry
7-May-2010
[16470]
hmm... need a delimeter in the key.. 
n/8497:9823 ;err invalid time
n/9384-5842; err invalid date
Steeve
7-May-2010
[16471x6]
n/123x345
... doesn't work...
you could use an integer to store the 2 values (but each one limited 
to 2^32)
>> a: 1234
== 1234
>> b: 345
== 345

>> key: b or shift a 32
== 5299989643609
or you can make a string with the 2 parts and the delimiter as a 
key, but it will cost more memory
>> m/("123-456"): 45
== 45
Terry
7-May-2010
[16477x2]
there's no end of keys .. could use zero as the delim i suppose
what would the mem cost be to use strings?
Steeve
7-May-2010
[16479]
there's theory and reality, just make some tests using dp
Terry
7-May-2010
[16480]
dp? duck pond?
Steeve
7-May-2010
[16481]
? dp
Terry
7-May-2010
[16482]
dp.. your acronym.. what does it mean?
Henrik
7-May-2010
[16483]
? dp
Steeve
7-May-2010
[16484]
it's a function of R3
Terry
7-May-2010
[16485]
is it possible to search the value of map! without looping?
Steeve
7-May-2010
[16486]
well... take that memory problem aside for the moment , and go with 
string keys :)
Terry
7-May-2010
[16487]
wow
Steeve
7-May-2010
[16488]
ouch, don't think so...
Actually maybe your real key is the value and not the key.
Terry
7-May-2010
[16489x3]
that is REALLY fast
1,000,000 GETs  in 1.387 seconds
can't use the value as the key.. it could be 1GB
no matter.. can't search by value in Redis either.. i have a work 
around
Steeve
7-May-2010
[16492x2]
or create a second map! with reversed key-values
ok, you can't
Terry
7-May-2010
[16494x3]
I'm going to try more test.. but if this is accurate,  this would 
be nearly 10x faster than Redis
great.. there goes my weekend :(
thanks for your help
Henrik
7-May-2010
[16497]
small detail that may be useful:

>> series? make map! []
== false
BrianH
7-May-2010
[16498]
DP: :DELTA-PROFILE, meaning change in profile. It's R3's built-in 
profiler. R3 also has a built-in timer, DT: :DELTA-TIME.
Maxim
7-May-2010
[16499]
happy to have helped  :-)
BrianH
7-May-2010
[16500]
Terry, try FIND VALUES-OF map value, if you can afford to trade memory 
overhead for the loop.
Terry
7-May-2010
[16501x2]
can you return the key somehow?
after some testing strings as keys and values are the way to go.. 
slightly faster ( to-binary? overhead?) and when you write the db 
to file, the strings are half the size
Graham
9-May-2010
[16503]
How does one sort on the 3 item in a seres?
Henrik
9-May-2010
[16504]
example?
BrianH
9-May-2010
[16505]
Use SORT/compare with an integer argument for the index of the records 
you want compared, and don't forget /skip for the record length. 
Like this:
>> sort/skip/compare [1 5 2 4 3 3 4 2 5 1] 2 2
== [5 1 4 2 3 3 2 4 1 5]
Sunanda
9-May-2010
[16506x2]
You mean using /skip and /compare to sort a series in sets?
s: [1 2 8 a   1 2 6 b   1 2 7 c]    ;; three sets of four items
sort/skip/compare s 4 [3]        ;; sort on the third item
== [1 2 6 b 1 2 7 c 1 2 8 a]
oops --- Brian just beat me to it!
Graham
9-May-2010
[16508]
thanks .. can someone update the docs http://www.rebol.com/docs/words/wsort.html
BrianH
9-May-2010
[16509]
Didn't know you could put the /compare index in a block. Can you 
specify more than one index?