1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 16
16
init-state
17
17
history))
18
18
19
+ (defn op-mops
20
+ " A lazy sequence of all [op mop] pairs from a history."
21
+ [history]
22
+ (mapcat (fn [op] (map (fn [mop] [op mop]) (:value op))) history))
23
+
19
24
(defn ext-reads
20
25
" Given a transaction, returns a map of keys to values for its external reads:
21
26
values that transaction observed which it did not write itself."
46
51
(assoc! ext k v))
47
52
(next txn)))
48
53
(persistent! ext))))
54
+
55
+ (defn int-write-mops
56
+ " Returns a map of keys to vectors of of all non-final write mops to that key."
57
+ [txn]
58
+ (loop [int (transient {})
59
+ txn txn]
60
+ (if (seq txn)
61
+ (let [[f k v :as mop] (first txn)]
62
+ (recur (if (= :r f)
63
+ int
64
+ (let [writes (get int k [])]
65
+ (assoc! int k (conj writes mop))))
66
+ (next txn)))
67
+ ; All done; trim final writes.
68
+ (->> int
69
+ persistent!
70
+ (keep (fn [[k vs]]
71
+ (when (< 1 (count vs))
72
+ [k (subvec vs 0 (dec (count vs)))])))
73
+ (into {})))))
0 commit comments