World: r3wp
[Core] Discuss core issues
older newer | first last |
Anton 27-Oct-2006 [5901x2] | I hope it's correct. |
Compared 10000 iterations on a 67k script. | |
Maxim 27-Oct-2006 [5903] | Carl has once said that most string iterating funcs are about equally fast in REBOL... the difference in this is that parse is only parsing the string once, whereas the previous one-liner does two replaces. So I guess that's the main reason. |
Anton 28-Oct-2006 [5904x5] | Makes sense. |
This version corrects a bug in the above parse rule: | |
to-rebol-line-terminators: func [ string [any-string!] /local here ][ parse/all string [ any [ to "^M" here: ["^M^/" (remove here) :here | "^M" (change here "^/")] ;thru "^M" here: ["^/" (remove back here) :here | (change back here "^/")] ] to end ] ] to-rebol-line-terminators bin: #{0d} bin | |
(and has an alternative way, but I think it will operate minutely slower.) | |
Actually, parse version looks only about 10% faster. When there is no work to do it is about twice as fast. | |
Gabriele 28-Oct-2006 [5909x2] | if you are doing to string! instead of as-string, then a copy version could be faster, when there are characters to remove. |
alternatively you could create a dummy port handler to let the native code do the job for you. | |
Anton 28-Oct-2006 [5911] | Hmm, both interesting ideas - much more than what I need for now - if the code gets any longer it's too unwieldy to be really useful. I will add these ideas as possible areas for investigation. |
Henrik 31-Oct-2006 [5912] | anyone built a function to find duplicate elements in a block and return them in a separate block? |
Geomol 31-Oct-2006 [5913x2] | blk: [a b b c b a] head foreach e unique blk [alter blk e] == [b b a] |
Ups, not separate block. Use copy! | |
MikeL 31-Oct-2006 [5915] | Henrik. Andrew created Tally.r It wasn't exactly what you asked but maybe there's some value there "Tallies up the values in a series, producing a block of [Value Count] pairs" http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=tally.r |
Gregg 1-Nov-2006 [5916] | ; Something like this? split-unique: func [block [any-block!] /local uniq dupe dest] [ uniq: copy [] dupe: copy [] foreach item block [ dest: either find/only uniq item [dupe] [uniq] append/only dest item ] reduce [uniq dupe] ] |
Maxim 1-Nov-2006 [5917x3] | Henrik: are you talking about intersect ? (part of rebol core) |
>> intersect [1 2 3 4 5] [4 5 6 7 8 9] == [4 5 6] | |
just reread your post... you want duplicates in the same block... sorry. | |
Henrik 1-Nov-2006 [5920] | yes, like: >> duplicates [1 1 2 2 3 4 5 5 6 7 8] == [1 2 5] |
Maxim 1-Nov-2006 [5921] | you got me into a spin, I rarely do this kind of fun , here is my best and shortest solution: (its also 3 times faster than Geomol's, using his block data ;-) duplicates: func [serie /local word][ remove-each word copy serie [same? find serie word find/last serie word] ] >> duplicates [a b b c b a] == [a b b b a] you can add the 'unique call to clean up the block if you like >> unique duplicates [1 1 2 2 3 4 5 5 6 7 8] == [1 2 5] |
Geomol 1-Nov-2006 [5922] | This one does what you want, I think: >> blk: [a b b c b a] >> unique head foreach e unique blk [alter copy blk e] == [a b] blk is untouched. |
Maxim 1-Nov-2006 [5923x2] | the competition is on ;-) |
the foreach is slow though, when compared to remove-each. | |
Geomol 1-Nov-2006 [5925x2] | And as a function: find-dups: func [blk] [unique head foreach e unique blk [alter copy blk e]] |
Maxim: Henrik didn't ask for speed! ;-) | |
Maxim 1-Nov-2006 [5927x2] | hehe... but I know he is addicted to it ;-) I had found my solution when I saw yours... so I just did a benchmark for the fun of it. |
you'll be intrigued to know that the unique call, is VERY slow. it was as long as my duplicates itself. | |
Geomol 1-Nov-2006 [5929] | Funny how the same thing can be done in so different ways with REBOL. I think, it's good. Choose the way, you like. Not many languages are like that. Again REBOL is much like a spoken language. You can say the same thing in lots of ways. Some say it with many words, some is short and precise, etc. |
Maxim 1-Nov-2006 [5930] | you have seen the old REBOL poetry discussion? IIRC they where on the mailing list... but not sure. |
Geomol 1-Nov-2006 [5931] | nope |
Maxim 1-Nov-2006 [5932] | some people where amazing. using only rebol core words and valid syntax... |
Geomol 1-Nov-2006 [5933] | :-) |
Maxim 1-Nov-2006 [5934] | writing subtle lines which often had nice printed results. |
Geomol 1-Nov-2006 [5935] | This one? http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-message.r?m=rmlJVXQ |
Maxim 1-Nov-2006 [5936] | hehehe... I guess those where part of it... |
Gabriele 1-Nov-2006 [5937x4] | >> s: now/precise duplicates-max blk difference now/precise s == 0:00:02.062 >> s: now/precise duplicates blk difference now/precise s == 0:00:00.031 >> length? blk == 10000 |
duplicates: func [block /local result value] [ result: make block! 16 parse sort copy block [ any [set value skip some value (append result value) | skip] ] result ] | |
mine does not need unique either | |
on a small block the speed is almost the same (mine a little bit faster) | |
Maxim 1-Nov-2006 [5941] | yes parse was the other solution, I was going to explore. |
Gabriele 1-Nov-2006 [5942x2] | i wonder if counting each value would be faster, probably not. sort being native helps a lot :) |
if blk is already sorted then it's even faster (no copy required either) | |
Maxim 1-Nov-2006 [5944] | indeed, in this situation, parse is much more flexible. |
Maxim 2-Nov-2006 [5945] | Gabriele, your solution does not support words! duplicates [ a b c ] ** Script Error: Invalid argument: a ** Where: duplicates |
Gabriele 2-Nov-2006 [5946] | where's LITERAL when you need it? |
[unknown: 5] 2-Nov-2006 [5947] | Does anyone have any information on what strength or methods that ENCLOAK uses? For example, what bit strength etc, algorithm etc,? |
Maxim 2-Nov-2006 [5948] | encloak is not an encryptor, its an obfuscator. |
[unknown: 5] 2-Nov-2006 [5949] | you mean like an xor type thing? |
Maxim 2-Nov-2006 [5950] | I don't know exactly, but I remember reading that its not a real encryption system. |
older newer | first last |