]> gitweb.factorcode.org Git - factor.git/commitdiff
tokyo.cabinet.abstract: Assoc protocol implementation for Tokyo Cabinet abstract...
authorBruno Deferrari <utizoc@gmail.com>
Wed, 17 Jun 2009 02:29:09 +0000 (23:29 -0300)
committerBruno Deferrari <utizoc@gmail.com>
Wed, 17 Jun 2009 02:29:09 +0000 (23:29 -0300)
extra/tokyo/cabinet/abstract/abstract.factor [new file with mode: 0644]
extra/tokyo/cabinet/abstract/authors.txt [new file with mode: 0644]

diff --git a/extra/tokyo/cabinet/abstract/abstract.factor b/extra/tokyo/cabinet/abstract/abstract.factor
new file mode 100644 (file)
index 0000000..6f3c576
--- /dev/null
@@ -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
+
+: <tokyo-abstractdb> ( 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 <int>          :> 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 (file)
index 0000000..f4a8cb1
--- /dev/null
@@ -0,0 +1 @@
+Bruno Deferrari