Skip to content

Commit 2950311

Browse files
committed
Refactor 1
There's a problem with how it refactored map->WriteHashMapCursor!
1 parent 4a5e5e0 commit 2950311

File tree

12 files changed

+697
-96
lines changed

12 files changed

+697
-96
lines changed

src/xitdb/array_list.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
(ns xitdb.array-list
22
(:require
33
[xitdb.common :as common]
4-
[xitdb.xitdb-util :as util])
4+
[xitdb.util.operations :as operations])
55
(:import
66
(io.github.radarroark.xitdb ReadArrayList ReadCursor WriteArrayList WriteCursor)))
77

88
(defn array-seq
99
[^ReadArrayList ral]
1010
"The cursors used must implement the IReadFromCursor protocol."
11-
(util/array-seq ral #(common/-read-from-cursor %)))
11+
(operations/array-seq ral #(common/-read-from-cursor %)))
1212

1313
(deftype XITDBArrayList [^ReadArrayList ral]
1414
clojure.lang.IPersistentCollection
@@ -89,7 +89,7 @@
8989

9090
clojure.core.protocols/IKVReduce
9191
(kv-reduce [this f init]
92-
(util/array-kv-reduce ral #(common/-read-from-cursor %) f init))
92+
(operations/array-kv-reduce ral #(common/-read-from-cursor %) f init))
9393

9494
java.util.Collection
9595
(^objects toArray [this]
@@ -133,11 +133,11 @@
133133

134134
(cons [this o]
135135
;;TODO: Figure out if it is correct to append to the end
136-
(util/array-list-assoc-value! wal (.count wal) (common/unwrap o))
136+
(operations/array-list-append-value! wal (common/unwrap o))
137137
this)
138138

139139
(empty [this]
140-
(util/array-list-empty! wal)
140+
(operations/array-list-empty! wal)
141141
this)
142142

143143
(equiv [this other]
@@ -158,7 +158,7 @@
158158

159159
clojure.lang.IPersistentVector
160160
(assocN [this i val]
161-
(util/array-list-assoc-value! wal i (common/unwrap val))
161+
(operations/array-list-assoc-value! wal i (common/unwrap val))
162162
this)
163163

164164
(length [this]
@@ -168,7 +168,7 @@
168168
(assoc [this k v]
169169
(when-not (integer? k)
170170
(throw (IllegalArgumentException. "Key must be integer")))
171-
(util/array-list-assoc-value! wal k (common/unwrap v))
171+
(operations/array-list-assoc-value! wal k (common/unwrap v))
172172
this)
173173

174174
(containsKey [this k]
@@ -191,7 +191,7 @@
191191

192192
clojure.core.protocols/IKVReduce
193193
(kv-reduce [this f init]
194-
(util/array-kv-reduce wal #(common/-read-from-cursor %) f init))
194+
(operations/array-kv-reduce wal #(common/-read-from-cursor %) f init))
195195

196196
clojure.lang.IObj
197197
(withMeta [this _]
@@ -207,7 +207,7 @@
207207

208208
clojure.lang.ITransientCollection
209209
(conj [this val]
210-
(util/array-list-append-value! wal (common/unwrap val))
210+
(operations/array-list-append-value! wal (common/unwrap val))
211211
this)
212212

213213
(persistent [this]
@@ -217,7 +217,7 @@
217217

218218
(pop [this]
219219
(let [value (common/-read-from-cursor (-> wal .-cursor))]
220-
(util/array-list-pop! wal)
220+
(operations/array-list-pop! wal)
221221
value))
222222

223223
common/ISlot

src/xitdb/common.clj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
(ns xitdb.common
2-
(:require
3-
[xitdb.xitdb-util :as util]))
1+
(ns xitdb.common)
42

53
(defprotocol ISlot
64
(-slot [this]))

src/xitdb/db.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(ns xitdb.db
22
(:require
3-
[xitdb.xitdb-types :as xtypes]
4-
[xitdb.xitdb-util :as util])
3+
[xitdb.util.conversion :as conversion]
4+
[xitdb.xitdb-types :as xtypes])
55
(:import
66
[io.github.radarroark.xitdb
7-
CoreBufferedFile CoreFile CoreMemory Hasher Database Database$ContextFunction
8-
RandomAccessBufferedFile RandomAccessMemory ReadArrayList WriteArrayList WriteHashMap Tag WriteCursor]
7+
CoreBufferedFile CoreFile CoreMemory Database Database$ContextFunction Hasher
8+
RandomAccessBufferedFile RandomAccessMemory ReadArrayList WriteArrayList WriteCursor]
99
[java.io File RandomAccessFile]
1010
[java.security MessageDigest]
1111
[java.util.concurrent.locks ReentrantLock]))
@@ -37,7 +37,7 @@
3737
Returns new history index."
3838
[^WriteArrayList history new-value]
3939
(append-context! history nil (fn [^WriteCursor cursor]
40-
(util/v->slot! cursor new-value))))
40+
(conversion/v->slot! cursor new-value))))
4141

4242
(defn open-database
4343
[filename ^String open-mode]
@@ -58,7 +58,7 @@
5858
(fn [^WriteCursor cursor]
5959
(let [obj (xtypes/read-from-cursor cursor true)]
6060
(let [retval (apply f (into [obj] args))]
61-
(.write cursor (xtypes/slot-for-value! cursor retval))))))))
61+
(.write cursor (conversion/v->slot! cursor retval))))))))
6262

6363
(defn xitdb-swap-with-lock!
6464
"Performs the 'swap!' operation while locking `db.lock`.

src/xitdb/hash_map.clj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns xitdb.hash-map
22
(:require
33
[xitdb.common :as common]
4-
[xitdb.xitdb-util :as util])
4+
[xitdb.util.conversion :as conversion]
5+
[xitdb.util.operations :as operations])
56
(:import
6-
[clojure.core.protocols IKVReduce]
7-
(io.github.radarroark.xitdb ReadCursor ReadHashMap WriteCursor WriteHashMap)))
7+
[io.github.radarroark.xitdb ReadCursor ReadHashMap WriteCursor WriteHashMap]))
88

99
(defn map-seq
1010
[rhm]
1111
"The cursors used must implement the IReadFromCursor protocol."
12-
(util/map-seq rhm #(common/-read-from-cursor %)))
12+
(operations/map-seq rhm #(common/-read-from-cursor %)))
1313

1414
(deftype XITDBHashMap [^ReadHashMap rhm]
1515

@@ -18,14 +18,14 @@
1818
(.valAt this key nil))
1919

2020
(valAt [this key not-found]
21-
(let [cursor (.getCursor rhm (util/db-key key))]
21+
(let [cursor (.getCursor rhm (conversion/db-key key))]
2222
(if (nil? cursor)
2323
not-found
2424
(common/-read-from-cursor cursor))))
2525

2626
clojure.lang.Associative
2727
(containsKey [this key]
28-
(not (nil? (.getCursor rhm (util/db-key key)))))
28+
(not (nil? (.getCursor rhm (conversion/db-key key)))))
2929

3030
(entryAt [this key]
3131
(let [v (.valAt this key nil)]
@@ -40,7 +40,7 @@
4040
(throw (UnsupportedOperationException. "XITDBHashMap is read-only")))
4141

4242
(count [this]
43-
(util/map-item-count rhm))
43+
(operations/map-item-count rhm))
4444

4545
clojure.lang.IPersistentCollection
4646
(cons [_ _]
@@ -77,7 +77,7 @@
7777

7878
clojure.core.protocols/IKVReduce
7979
(kv-reduce [this f init]
80-
(util/map-kv-reduce rhm #(common/-read-from-cursor %) f init))
80+
(operations/map-kv-reduce rhm #(common/-read-from-cursor %) f init))
8181

8282
common/IUnwrap
8383
(-unwrap [this]
@@ -121,7 +121,7 @@
121121
this)
122122

123123
(empty [this]
124-
(util/map-empty! whm)
124+
(operations/map-empty! whm)
125125
this)
126126

127127
(equiv [this other]
@@ -130,41 +130,41 @@
130130
(seq this))))
131131
clojure.lang.Associative
132132
(assoc [this k v]
133-
(util/map-assoc-value! whm k (common/unwrap v))
133+
(operations/map-assoc-value! whm k (common/unwrap v))
134134
this)
135135

136136
(containsKey [this key]
137-
(util/map-contains-key? whm key))
137+
(operations/map-contains-key? whm key))
138138

139139
(entryAt [this key]
140140
(when (.containsKey this key)
141141
(clojure.lang.MapEntry. key (.valAt this key))))
142142

143143
clojure.lang.IPersistentMap
144144
(without [this key]
145-
(util/map-dissoc-key! whm key)
145+
(operations/map-dissoc-key! whm key)
146146
this)
147147

148148
(count [this]
149-
(util/map-item-count whm))
149+
(operations/map-item-count whm))
150150

151151
clojure.lang.ILookup
152152
(valAt [this key]
153153
(.valAt this key nil))
154154

155155
(valAt [this key not-found]
156-
(let [cursor (util/map-read-cursor whm key)]
156+
(let [cursor (operations/map-read-cursor whm key)]
157157
(if (nil? cursor)
158158
not-found
159-
(common/-read-from-cursor (util/map-write-cursor whm key)))))
159+
(common/-read-from-cursor (operations/map-write-cursor whm key)))))
160160

161161
clojure.lang.Seqable
162162
(seq [this]
163163
(map-seq whm))
164164

165165
clojure.core.protocols/IKVReduce
166166
(kv-reduce [this f init]
167-
(util/map-kv-reduce whm #(common/-read-from-cursor %) f init))
167+
(operations/map-kv-reduce whm #(common/-read-from-cursor %) f init))
168168

169169
common/ISlot
170170
(-slot [this]

src/xitdb/hash_set.clj

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
(ns xitdb.hash-set
22
(:require
33
[xitdb.common :as common]
4-
[xitdb.xitdb-util :as util])
4+
[xitdb.util.conversion :as conversion]
5+
[xitdb.util.operations :as operations])
56
(:import
6-
(io.github.radarroark.xitdb ReadCursor ReadHashMap WriteCursor WriteHashMap)))
7+
[io.github.radarroark.xitdb ReadHashMap WriteCursor WriteHashMap]))
78

89
(defn set-seq
910
[rhm]
1011
"The cursors used must implement the IReadFromCursor protocol."
11-
(map val (util/map-seq rhm #(common/-read-from-cursor %))))
12+
(map val (operations/map-seq rhm #(common/-read-from-cursor %))))
1213

1314
(deftype XITDBHashSet [^ReadHashMap rhm]
1415
clojure.lang.IPersistentSet
1516
(disjoin [_ k]
1617
(throw (UnsupportedOperationException. "XITDBHashSet is read-only")))
1718

1819
(contains [this k]
19-
(not (nil? (.getCursor rhm (util/db-key (if (nil? k) 0 (.hashCode k)))))))
20+
(not (nil? (.getCursor rhm (conversion/db-key (if (nil? k) 0 (.hashCode k)))))))
2021

2122
(get [this k]
2223
(when (.contains this k)
@@ -35,7 +36,7 @@
3536
(every? #(.contains this %) other)))
3637

3738
(count [_]
38-
(util/map-item-count rhm))
39+
(operations/map-item-count rhm))
3940

4041
clojure.lang.Seqable
4142
(seq [_]
@@ -86,23 +87,23 @@
8687
(deftype XITDBWriteHashSet [^WriteHashMap whm]
8788
clojure.lang.IPersistentSet
8889
(disjoin [this k]
89-
(util/map-dissoc-key! whm (.hashCode k))
90+
(operations/map-dissoc-key! whm (.hashCode k))
9091
this)
9192

9293
(contains [this k]
93-
(util/map-contains-key? whm (.hashCode k)))
94+
(operations/map-contains-key? whm (.hashCode k)))
9495

9596
(get [this k]
9697
(when (.contains this k)
9798
k))
9899

99100
clojure.lang.IPersistentCollection
100101
(cons [this o]
101-
(util/set-assoc-value! whm (common/unwrap o))
102+
(operations/set-assoc-value! whm (common/unwrap o))
102103
this)
103104

104105
(empty [this]
105-
(util/set-empty! whm)
106+
(operations/set-empty! whm)
106107
this)
107108

108109
(equiv [this other]
@@ -111,7 +112,7 @@
111112
(every? #(.contains this %) other)))
112113

113114
(count [_]
114-
(util/map-item-count whm))
115+
(operations/map-item-count whm))
115116

116117
clojure.lang.Seqable
117118
(seq [_]
@@ -140,7 +141,7 @@
140141

141142
;; Constructor functions
142143
(defn xwrite-hash-set [^WriteCursor write-cursor]
143-
(let [whm (util/init-hash-set! write-cursor)]
144+
(let [whm (operations/init-hash-set! write-cursor)]
144145
(->XITDBWriteHashSet whm)))
145146

146147
(defn xhash-set [^ReadHashMap read-cursor]

src/xitdb/linked_list.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
(ns xitdb.linked-list
22
(:require
33
[xitdb.common :as common]
4-
[xitdb.xitdb-util :as util])
4+
[xitdb.util.conversion :as conversion]
5+
[xitdb.util.operations :as operations])
56
(:import
6-
[io.github.radarroark.xitdb ReadLinkedArrayList ReadCursor ReadHashMap Tag
7-
Slot WriteLinkedArrayList WriteCursor]))
7+
[io.github.radarroark.xitdb ReadCursor ReadLinkedArrayList WriteCursor WriteLinkedArrayList]))
88

99
(defn array-seq
1010
[^ReadLinkedArrayList rlal]
1111
"The cursors used must implement the IReadFromCursor protocol."
12-
(util/linked-array-seq rlal #(common/-read-from-cursor %)))
12+
(operations/linked-array-seq rlal #(common/-read-from-cursor %)))
1313

1414
(deftype XITDBLinkedArrayList [^ReadLinkedArrayList rlal]
1515
clojure.lang.IPersistentCollection
@@ -112,13 +112,13 @@
112112

113113
(cons [this o]
114114
;; TODO: This should insert at position 0
115-
(util/linked-array-list-insert-value! wlal 0 (common/unwrap o))
115+
(operations/linked-array-list-insert-value! wlal 0 (common/unwrap o))
116116
this)
117117

118118
(empty [this]
119119
;; Assuming similar empty behavior as arrays
120120
(let [^WriteCursor cursor (-> wlal .cursor)]
121-
(.write cursor (util/v->slot! cursor (list))))
121+
(.write cursor (conversion/v->slot! cursor (list))))
122122
this)
123123

124124
(equiv [this other]
@@ -178,7 +178,7 @@
178178

179179
clojure.lang.ITransientCollection
180180
(conj [this val]
181-
(util/linked-array-list-append-value! wlal (common/unwrap val))
181+
(operations/linked-array-list-append-value! wlal (common/unwrap val))
182182
this)
183183

184184
(persistent [this]
@@ -192,7 +192,7 @@
192192

193193
(pop [this]
194194
(if (pos? (.count wlal))
195-
(util/linked-array-list-pop! wlal)
195+
(operations/linked-array-list-pop! wlal)
196196
(throw (IllegalStateException. "Can't pop empty list")))
197197
this)
198198

0 commit comments

Comments
 (0)