]> gitweb.factorcode.org Git - factor.git/commitdiff
mongodb/couchdb: use associate where possible.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 20 Jul 2012 16:37:54 +0000 (09:37 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 20 Jul 2012 16:41:05 +0000 (09:41 -0700)
extra/couchdb/couchdb.factor
extra/mongodb/benchmark/benchmark.factor
extra/mongodb/tuple/collection/collection.factor
extra/mongodb/tuple/tuple.factor

index ed5dd1268fa9042a445a176879a9e454a6dbad04..9e1e49babd26e23f54b508ac5593597876a54b22 100644 (file)
@@ -156,7 +156,7 @@ C: <db> db
     <json-post-data> couch get db-url "_temp_view" append couch-post ;
 
 : temp-view-map ( map -- results )
-    "map" H{ } clone [ set-at ] keep temp-view ;
+    "map" associate temp-view ;
 
 : save-doc-as ( assoc id -- )
     [ dup <json-post-data> ] dip id-url couch-put response-ok
index 9826923df092eb11deb919b21918876814823491..dac4fcbeb802ef01b16344071ac65f41481fec0b 100644 (file)
@@ -1,6 +1,7 @@
 USING: calendar math fry kernel assocs math.ranges bson.reader io.streams.byte-array
 sequences formatting combinators namespaces io tools.time prettyprint io.encodings.binary
-accessors words mongodb.driver strings math.parser bson.writer ;
+accessors words mongodb.driver strings math.parser bson.writer
+hashtables ;
 FROM: mongodb.driver => find ;
 FROM: memory => gc ;
 
@@ -183,7 +184,7 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
 
 : (check-find-result) ( result -- )
     "x" check-for-key ; inline
-  
+
 : (find) ( cursor -- )
     [ find [ (check-find-result) ] each (find) ] when* ; inline recursive
 
@@ -191,15 +192,15 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
     drop
     [ trial-size
       collection-name
-      trial-size 2 / "x" H{ } clone [ set-at ] keep
+      trial-size 2 / "x" associate
       '[ _ _ <query> 1 limit (find) ] times ] ;
-  
+
 : find-all ( quot -- quot: ( -- ) )
     drop
     collection-name
     H{ } clone
     '[ _ _ <query> (find) ] ;
-  
+
 : find-range ( quot -- quot: ( -- ) )
     drop
     [ trial-size batch-size /i
@@ -211,7 +212,7 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
 
 : batch ( -- )
     result [ t >>batch ] change ; inline
-   
+
 : index ( -- )
     result [ t >>index ] change ; inline
 
@@ -260,7 +261,7 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
     "Deserialization Tests" print
     print-separator-bold
     \ deserialize [bench-quot] '[ _ call( doc-word -- ) ] each ; 
-    
+
 : run-insert-bench ( doc-word-seq feat-seq -- )
     "Insert Tests" print
     print-separator-bold 
@@ -281,7 +282,7 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
     print-separator-bold
     \ find-range [bench-quot] '[ _ call( doc-word -- ) ] each ; 
 
-    
+
 : run-benchmarks ( -- )
     "db" "db" get* "host" "127.0.0.1" get* "port" 27017 get* ensure-number <mdb>
     [ print-header
@@ -307,8 +308,8 @@ CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" }
       { { } { index } } run-find-all-bench
       ! find-range
       { small-doc medium-doc large-doc }
-      { { } { index } } run-find-range-bench        
+      { { } { index } } run-find-range-bench
     ] with-db ;
-        
+
 MAIN: run-benchmarks
 
index 272fc3df1b7c7dd282a45f1b52ac46cda2537fcc..c3a8ef7681c957c72eb58c7e9d32e028f98d00a1 100644 (file)
@@ -1,7 +1,7 @@
-
 USING: accessors arrays assocs bson.constants classes classes.tuple
 combinators continuations fry kernel mongodb.driver sequences strings
-vectors words combinators.smart literals memoize slots constructors ;
+vectors words combinators.smart literals memoize slots constructors
+hashtables ;
 
 IN: mongodb.tuple
 
@@ -88,8 +88,8 @@ GENERIC: mdb-index-map ( tuple -- sequence )
 : user-defined-key-index ( class -- assoc )
     mdb-slot-map user-defined-key
     [ drop [ "user-defined-key-index" 1 ] dip
-      H{ } clone [ set-at ] keep <tuple-index> t >>unique?
-      [ ] [ name>> ] bi  H{ } clone [ set-at ] keep
+      associate <tuple-index> t >>unique?
+      [ ] [ name>> ] bi associate
     ] [ 2drop H{ } clone ] if ;
 
 
index 1568572bfb94b19aca1f493bb70f36e394ae10e7..428e5f7bdb9747e0980cccc68210332ea110ba8f 100644 (file)
@@ -1,5 +1,7 @@
 USING: accessors assocs classes.mixin classes.tuple
-classes.tuple.parser compiler.units fry kernel sequences mongodb.driver
+classes.tuple.parser compiler.units fry kernel sequences
+hashtables
+mongodb.driver
 mongodb.msg mongodb.tuple.collection 
 mongodb.tuple.persistent mongodb.tuple.state strings ;
 FROM: mongodb.driver => update delete find count ;
@@ -45,7 +47,7 @@ DEFER: tuple>query
 GENERIC: id-selector ( object -- selector )
 
 M: toid id-selector
-   [ value>> ] [ key>> ] bi H{ } clone [ set-at ] keep ; inline
+   [ value>> ] [ key>> ] bi associate ; inline
 
 M: mdb-persistent id-selector
    >toid id-selector ;