From: Bruno Deferrari Date: Wed, 17 Jun 2009 02:29:09 +0000 (-0300) Subject: tokyo.cabinet.abstract: Assoc protocol implementation for Tokyo Cabinet abstract... X-Git-Tag: 0.97~6105^2^2~9 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=ce47a54562d269bef489f5aa9b25c05b46cb4439 tokyo.cabinet.abstract: Assoc protocol implementation for Tokyo Cabinet abstract db api --- diff --git a/extra/tokyo/cabinet/abstract/abstract.factor b/extra/tokyo/cabinet/abstract/abstract.factor new file mode 100644 index 0000000000..6f3c5768b8 --- /dev/null +++ b/extra/tokyo/cabinet/abstract/abstract.factor @@ -0,0 +1,51 @@ +! Copyright (C) 2009 Bruno Deferrari +! See http://factorcode.org/license.txt for BSD license. +USING: accessors alien.c-types assocs destructors kernel libc locals +sequences serialize tokyo.alien.tcadb ; +IN: tokyo.cabinet.abstract + +TUPLE: tokyo-abstractdb handle disposed ; + +INSTANCE: tokyo-abstractdb assoc + +: ( name -- tokyo-abstractdb ) + tcadbnew [ swap tcadbopen drop ] keep + tokyo-abstractdb new [ (>>handle) ] keep ; + +M: tokyo-abstractdb dispose* [ tcadbdel f ] change-handle drop ; + +M:: tokyo-abstractdb at* ( key db -- value/f ? ) + 0 :> sizeout + db handle>> :> handle + key object>bytes :> kbytes + kbytes length :> key-size + handle kbytes key-size sizeout tcadbget :> output + output [ + [ sizeout *int memory>byte-array bytes>object t ] [ drop ] bi + ] [ f f ] if* ; + +M: tokyo-abstractdb assoc-size ( db -- size ) handle>> tcadbrnum ; + +! FIXME: implement +! M: tokyo-abstractdb >alist ( db -- alist ) +! handle>> ; + +M:: tokyo-abstractdb set-at ( value key db -- ) + db handle>> :> handle + key object>bytes :> kbytes + kbytes length :> key-size + value object>bytes :> vbytes + vbytes length :> value-size + handle kbytes key-size vbytes value-size tcadbput drop ; + +M:: tokyo-abstractdb delete-at ( key db -- ) + db handle>> :> handle + key object>bytes :> kbytes + kbytes length :> key-size + handle kbytes key-size tcadbout drop ; + +M: tokyo-abstractdb clear-assoc ( db -- ) handle>> tcadbvanish drop ; + +M: tokyo-abstractdb equal? assoc= ; + +M: tokyo-abstractdb hashcode* assoc-hashcode ; diff --git a/extra/tokyo/cabinet/abstract/authors.txt b/extra/tokyo/cabinet/abstract/authors.txt new file mode 100644 index 0000000000..f4a8cb1dc2 --- /dev/null +++ b/extra/tokyo/cabinet/abstract/authors.txt @@ -0,0 +1 @@ +Bruno Deferrari