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 <[EMAIL PROTECTED]>

Amiga is a trademark of Amiga Inc.
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
  ]
]

Reply via email to