Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

bitset actions?

 [1/6] from: Rebolinth:nodep:dds:nl at: 24-Dec-2003 22:39


Hallo All, Is there a way to 'pick on bitsets? Im looking for a way to select a range or a single character from a bitset on a specific location, but i can emagine that the 'bitset does not do serie handing the way series does. I thought bitsets where smaler (and quicker using parsing) , but i can emagine using a normal string range would even do the trick as quick as well? (which im currently using in my program) A simple example to visualise the problem.. ;;; example 1 t1: charset [ #"a" - #"q" #"x" - #"z" ] t2: charset [ #"A" - #"Q" #"t" - #"v" ] pick t2 index? find t1 #"x" ;;; example 2 t1: charset "KHEWWKJEWBLKUWEOFBIYTEWQFBOYTEWUEQIUFBITWQUFB" t2: charset "QWEIRLUYQWIURYLQWUYREOIWQUYROIQUWYEOIRUYWQEOI" pick t2 index? find t1 #"x" The above does not work ... But is there a way to compare 2 bitsets ranges with eachother, using parse perhpas?, like the above, but without ..union..etc...? Regards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"

 [2/6] from: brett:codeconscious at: 10-Oct-2003 16:36


Hi Rebolinth, I am not sure about what you are trying to achieve, but I think you may have the wrong idea about bitsets. Here are some examples to help you. Bitsets are not series:
>> series? make bitset! 8
== false However they do have a length - the number of bits (always a multiple of 8):
>> length? make bitset! 8
== 8
>> length? make bitset! 16
== 16 The Charset function just creates bitsets from the character you specify:
>> source charset
charset: func [ "Makes a bitset of chars for the parse function." chars [string! block!] ][ make bitset! chars ] The number of bits in a bitset created by the Charset function is (currently) 256 - one bit to represent each possible character:
>> length? charset ""
== 256 With bitsets you are *only* turning some bits on and some bits off by a position number. Characters are translated to a position.
> Is there a way to 'pick on bitsets?
You use Find to test if a bit corresponding to your value is set:
>> find charset "ab" "a"
== true
>> find charset "ab" "b"
== true
>> find charset "ab" "c"
== none You can use the ascii value:
>> find charset "*" 42
== true You can set bits corresponding to your value with Insert:
>> find insert charset "ab" "d" "d"
== true To enumerate all the characters represented in a bitset created using charset use a loop (notice also that the bitset does not record duplicates): bitset: charset "aaaaybcx" chars: copy {} for i 0 (subtract length? bitset 1) 1 [ if find bitset i [append chars to-char i] ] ?? chars When using Parse bitsets can be used for matching against a set of characters: my-chars: charset "xyz" is simpler and probably more efficient than my-chars: [#"x" | #"y" | #"z"] You can use bitsets with Find too:
>> find "123x5" charset "xyz"
== "x5" Clear, Empty?, Union, Interset, Exclude, Difference, Negate and Complement can be used on bitsets Example using just a small bitset.
>> find insert make bitset! 8 6 6
== true Outside the range:
>> insert make bitset! 8 9
** Script Error: Invalid argument: 9 ** Near: insert make bitset! 8 9
>> find make bitset! 8 9
** Script Error: Invalid argument: 9 ** Near: find make bitset! 8 9 Cheers, Brett.

 [3/6] from: Rebolinth:nodep:dds:nl at: 10-Oct-2003 12:49


Hello Brett, I know how bitsets work, Your reply confirms the fact that the use of bitsets is useless for my purpous, except for comparisons against a string but there is no function to get indexes from bitsets.. Never the less thanks for the 'enhanced' reply ;-) Regards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"

 [4/6] from: brett:codeconscious at: 10-Oct-2003 23:34


> I know how bitsets work,
Ah.
> Your reply confirms the fact that the use of bitsets is useless for my
purpous,
> except for comparisons against a string but there is no function to get
indexes from bitsets.. ...index from bitsets.. Hmmmm. To make bitsets more useful I would like to see Select take a bitset as its index argument. So that if you had a script like this: bitset: make bitset! 8 insert bitset 3 insert bitset 5 select/many [a b c d e...] bitset it could return [c e] as a result. Similar idea for Pick At etc. Could be good for complex "database queries". If this is what you originally meant, then I apologise for misunderstanding you.
> Never the less thanks for the 'enhanced' reply ;-)
No problem. Sometimes an enhanced reply is just what is needed, sometimes not. Sometimes it is just what someone else on the list needs :^) Brett.

 [5/6] from: Rebolinth:nodep:dds:nl at: 10-Oct-2003 16:33


Hello Brett, Seems there is more animo for Bitset queries ;-) Perhpas RT has some input on the issue? (are they on holiday?) (R)egards, Norman. -- Conversation/lunch: "How do you Eat your Rebol in the Morning?"

 [6/6] from: antonr:iinet:au at: 13-Oct-2003 11:06


There is a function. It just hasn't been written yet. :) I guess it is up to you. I'll just say that it can be done using mold. Anton.