--- /dev/null
+! Copyright (C) 2009 Bruno Deferrari
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.c-types arrays assocs destructors
+kernel locals sequences serialize vectors
+tokyo.alien.tcadb tokyo.alien.tcutil tokyo.utils ;
+IN: tokyo.abstractdb
+
+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 [
+ [ memory>object ] [ tcfree ] bi t
+ ] [ f f ] if* ;
+
+M: tokyo-abstractdb assoc-size ( db -- size ) handle>> tcadbrnum ;
+
+! FIXME: make this nicer
+M:: tokyo-abstractdb >alist ( db -- alist )
+ db handle>> :> handle
+ 0 <int> :> size-out
+ db assoc-size <vector> :> keys
+ handle tcadbiterinit drop
+ [ handle size-out tcadbiternext dup ] [
+ [ memory>object ] [ tcfree ] bi
+ keys push
+ ] while drop
+ keys [ dup db at 2array ] { } map-as ;
+
+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 ;
--- /dev/null
+Bruno Deferrari
--- /dev/null
+Higher level API for Tokyo Cabinet's Abstract database API. Implements the associative protocol.
+++ /dev/null
-! Copyright (C) 2009 Bruno Deferrari
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs destructors
-io io.streams.memory kernel libc locals
-sequences serialize tokyo.alien.tcadb tokyo.alien.tcutil vectors ;
-IN: tokyo.cabinet.abstract
-
-TUPLE: tokyo-abstractdb handle disposed ;
-
-<PRIVATE
-: with-memory-reader ( memory quot -- )
- [ <memory-stream> ] dip with-input-stream* ; inline
-
-: memory>object ( memory -- object )
- [ deserialize ] with-memory-reader ;
-PRIVATE>
-
-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 [
- [ memory>object ] [ tcfree ] bi t
- ] [ f f ] if* ;
-
-M: tokyo-abstractdb assoc-size ( db -- size ) handle>> tcadbrnum ;
-
-! FIXME: make this nicer
-M:: tokyo-abstractdb >alist ( db -- alist )
- db handle>> :> handle
- 0 <int> :> size-out
- db assoc-size <vector> :> keys
- handle tcadbiterinit drop
- [ handle size-out tcadbiternext dup ] [
- [ memory>object ] [ tcfree ] bi
- keys push
- ] while drop
- keys [ dup db at 2array ] { } map-as ;
-
-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 ;
+++ /dev/null
-Bruno Deferrari
+++ /dev/null
-Higher level API for Tokyo Cabinet's Abstract database API. Implements the associative protocol.
--- /dev/null
+Bruno Deferrari
--- /dev/null
+Some utility words used by the tokyo vocabs
--- /dev/null
+! Copyright (C) 2009 Bruno Deferrari
+! See http://factorcode.org/license.txt for BSD license.
+USING: io io.streams.memory serialize kernel ;
+IN: tokyo.utils
+
+: with-memory-reader ( memory quot -- )
+ [ <memory-stream> ] dip with-input-stream* ; inline
+
+: memory>object ( memory -- object )
+ [ deserialize ] with-memory-reader ;