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

[REBOL] Associative data storage function library

From: joel::neely::fedex::com at: 22-Sep-2000 17:22

This is a multi-part message in MIME format. --------------EFFDA6170AF07702FFAE4693 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii As a follow-up to the previous post, I also put together a function library equivalent to the OO version. (I know this is reinventing the wheel, but I wanted total equivalence for reasons that will be made clear in the following post.) -jn- --------------EFFDA6170AF07702FFAE4693 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii; name="assocf.r" Content-Disposition: inline; filename="assocf.r" REBOL [ Title: "Minimal Associative Data Store - Function Version" File: %assocf.r Date: 20-Sep-2000 Author: "Joel Neely" Purpose: { Function-based implementation of associative data store, using object for data only, with arbitrary data types for keys and values. } ] assoc.object: make object! [ _keys: copy [] _vals: copy [] ] assoc.clear: func [ads [object!]] [ ads/_keys: copy [] ads/_vals: copy [] ads ] assoc.empty?: func [ads [object!]] [system/words/empty? ads/_keys] assoc.length?: func [ads [object!]] [system/words/length? ads/_keys] func [/local r] [r: make assoc.object [] assoc.clear r] assoc.put: func [ads [object!] k [any-type!] v [any-type!] /local p] [ either found? p: find/only ads/_keys k [ change/only at ads/_vals index? p v ][ append/only ads/_keys k append/only ads/_vals v ] v ] assoc.get: func [ads [object!] k [any-type!] /local p] [ either none? p: find/only ads/_keys k [ none ][ pick ads/_vals index? p ] ] assoc.delete: func [ads [object!] k [any-type!] /local p v] [ either none? p: find/only ads/_keys k [ none ][ k: pick ads/_vals p: index? p remove at ads/_keys p remove at ads/_vals p k ] ] assoc.keys: func [ads [object!]] [copy ads/_keys] --------------EFFDA6170AF07702FFAE4693--