#3: Still problems in index-vertices, I think

This commit is contained in:
Simon Brooke 2020-05-30 14:09:14 +01:00
parent 7442673cbf
commit f93432a241
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
2 changed files with 42 additions and 25 deletions

View file

@ -63,14 +63,31 @@
2. `o` is not a map; 2. `o` is not a map;
3. `o` does not have a value for the key `:walkmap.id/id`." 3. `o` does not have a value for the key `:walkmap.id/id`."
[s o] [s o]
(assoc (u/deep-merge
s s
:vertex-index {:vertex-index
(reduce (reduce
u/deep-merge u/deep-merge
{}
(map (map
#(index-vertex s o %) #(index-vertex s o %)
(vertices o))))) (:vertices o)))}))
(defn in-retrieve-map
"Internal to `in-retrieve`, q.v. Handle the case where `x` is a map.
Separated out for debugging/unit testing purposes. Use at your own peril."
[x s]
(let [v (reduce
(fn [m k]
(assoc m k (in-retrieve (x k) s)))
{}
(keys (dissoc x :walkmap.id/id)))
id (:walkmap.id/id x)]
(if id
(assoc
v
:walkmap.id/id
(:walkmap.id/id x)))))
(defn in-retrieve (defn in-retrieve
"Internal guts of `retrieve`, q.v. `x` can be anything; `s` must be a "Internal guts of `retrieve`, q.v. `x` can be anything; `s` must be a
@ -84,13 +101,7 @@
(in-retrieve (s x) s) (in-retrieve (s x) s)
x) x)
;; if it's a map, for every key which is not `:walkmap.id/id`, recurse. ;; if it's a map, for every key which is not `:walkmap.id/id`, recurse.
(map? x) (reduce (map? x) (in-retrieve-map x s)
(fn [m k]
(if (= k :walkmap.id/id)
k
(assoc m k (in-retrieve (x k) s))))
{}
(keys x))
(coll? x) (map #(in-retrieve % s) x) (coll? x) (map #(in-retrieve % s) x)
:else x)) :else x))
@ -140,18 +151,22 @@
1. `s` is not a map; 1. `s` is not a map;
2. `o` is not a recognisable walkmap object" 2. `o` is not a recognisable walkmap object"
([o] ([o]
(store {} o)) (store o {}))
([o s] ([o s]
;; (when-not (:walkmap.id/id o) (when-not (:walkmap.id/id o)
;; (throw (throw
;; (IllegalArgumentException. (IllegalArgumentException.
;; (str "Not a walkmap object: no value for `:walkmap.id/id`: " (str "Not a walkmap object: no value for `:walkmap.id/id`: "
;; (u/kind-type o))))) (u/kind-type o)))))
;; (when-not (map? s) (when-not (map? s)
;; (throw (throw
;; (IllegalArgumentException. (IllegalArgumentException.
;; (str "Superstructure must be a map: " (u/kind-type s))))) (str "Superstructure must be a map: " (u/kind-type s)))))
(assoc (assoc
(u/deep-merge s (in-store-find-objects o)) (u/deep-merge s (in-store-find-objects o))
(:walkmap.id/id o) (:walkmap.id/id o)
(in-store-replace-with-keys o)))) (in-store-replace-with-keys o)
:vertex-index
(u/deep-merge
(index-vertices s o)
(:vertex-index s)))))

View file

@ -5,6 +5,8 @@
(defn deep-merge (defn deep-merge
"Recursively merges maps. If vals are not maps, the last value wins." "Recursively merges maps. If vals are not maps, the last value wins."
;; TODO: not my implementation, not sure I entirely trust it. ;; TODO: not my implementation, not sure I entirely trust it.
;; TODO TODO: if we are to successfully merge walkmap objects, we must
;; return, on each object, the union of its tags if any.
[& vals] [& vals]
(if (every? map? vals) (if (every? map? vals)
(apply merge-with deep-merge vals) (apply merge-with deep-merge vals)