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

[REBOL] Essay on Associative Data Stores Re:

From: ole_f:post3:tele:dk at: 18-Sep-2000 12:45

If you read this, you are using an old mail reader. The solution if you have difficulty reading the rest of this mail is getting hold of newer, MIME-compliant software. --X=Boundary=X Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Wordwrap: 78 Hi Joel, 16-Sep-2000 you wrote:
>1.1. Keys and values are not distinguised. >1.2. Storage management/economy require extra code to > handle replacement of values for existing keys. >1.3. The block! type doesn't appear to be supported as a key > in a manner consistent with other data types.
I've attached some functions for manipulating with an associative data structure. I personally think they suffice for my normal uses, but I'm looking forward to your comments (though, please keep it short then, I don't have the time to read through all that ASCII ;-) ). BTW, using a hash! for the "keys" array would probably be a better idea than just using a block!, as I currently do. _If_ find/only works faster on hash! lists, that is (it should be, but I don't know). Kind regards, -- Ole Friis <[ole_f--post3--tele--dk]> Amiga is a trademark of Amiga Inc. --X=Boundary=X Content-Type: text/plain; charset=US-ASCII; name="ADS.r" Content-Transfer-Encoding: 7bit REBOL [] create-ads: func [ "Creates a new associative data structure" ][ make object! [ keys: copy [] values: copy [] ] ] lookup-ads: func [ "Returns the value associated with the key" ads [object!] "The associative data structure" key [any-type!] "Key" /local t-list ][ if found? t-list: find/only ads/keys key [ pick ads/values index? t-list ] ] associate-ads: func [ "Appends the new key/value pair in the data structure" ads [object!] "The associative data structure" key [any-type!] "Key" value [any-type!] "Value" /local t-list ][ either found? t-list: find/only ads/keys key [ change/only at ads/values index? t-list value ][ append/only ads/keys key append/only ads/values value ] ] --X=Boundary=X--