Skip to content

Commit

Permalink
Implement more efficient hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
bplatz committed Feb 23, 2025
1 parent 20531fd commit bd83599
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/clj/fluree/db/json_ld/iri.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,19 @@
#?@(:clj [Object
(equals [this sid]
(sid-equiv? this sid))
(hashCode [this] (hash (seq this)))
(hashCode [_]
(clojure.lang.Util/hashCombine namespace-code (hash name)))

clojure.lang.IHashEq
(hasheq [this] (hash (seq this)))
(hasheq [_]
(clojure.lang.Util/hashCombine namespace-code (hash name)))

java.lang.Comparable
(compareTo [this other] (compare-SIDs this other))]

(-hash [this] (hash (seq this)))
:cljs [IHash
(-hash [_]
(hash-combine namespace-code (hash name)))

IEquiv
(-equiv [this sid] (sid-equiv? this sid))
Expand Down Expand Up @@ -145,7 +148,7 @@
; (.write w (str "#=" `(->sid ~ns-code ~nme))))))

(defn compare-SIDs
[^SID sid1 ^SID sid2]
[sid1 sid2]
(when-not (instance? SID sid2)
(throw (ex-info "Can't compare an SID to another type"
{:status 500 :error :db/unexpected-error})))
Expand Down
16 changes: 8 additions & 8 deletions test/fluree/db/query/property_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@
loaded @(fluree/load conn ledger-id)
dbl (fluree/db loaded)]
(testing "before load"
(is (= [{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}
{"id" "ex:dan", "ex:givenName" "Dan"}]
(is (= [{"id" "ex:dan", "ex:givenName" "Dan"}
{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}]
@(fluree/query db2 {"@context" context
"select" {"?s" ["*"]}
"where" {"@id" "?s", "ex:givenName" "?o"}})))
(is (= [{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}
{"id" "ex:dan", "ex:givenName" "Dan"}]
(is (= [{"id" "ex:dan", "ex:givenName" "Dan"}
{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}]
@(fluree/query db2 {"@context" context
"select" {"?s" ["*"]}
"where" {"@id" "?s", "ex:firstName" "?o"}})))
Expand All @@ -270,13 +270,13 @@
"ex:fool" "?fool"}}))
"handle list values"))
(testing "after load"
(is (= [{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}
{"id" "ex:dan", "ex:givenName" "Dan"}]
(is (= [{"id" "ex:dan", "ex:givenName" "Dan"}
{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}]
@(fluree/query dbl {"@context" context
"select" {"?s" ["*"]}
"where" {"@id" "?s", "ex:givenName" "?o"}})))
(is (= [{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}
{"id" "ex:dan", "ex:givenName" "Dan"}]
(is (= [{"id" "ex:dan", "ex:givenName" "Dan"}
{"id" "ex:andrew", "ex:firstName" "Andrew", "ex:age" 35}]
@(fluree/query dbl {"@context" context
"select" {"?s" ["*"]}
"where" {"@id" "?s", "ex:firstName" "?o"}})))
Expand Down
2 changes: 1 addition & 1 deletion test/fluree/db/shacl/shacl_logical_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ Subject :ex/john violates constraint :sh/not of shape :ex/UserShape - :ex/john c
"sh:focusNode" "ex:Named",
"sh:constraintComponent" "sh:xone",
"sh:sourceShape" "ex:orShape",
"sh:value" ["Washington" "George" "George Washington"],
"sh:value" ["George" "George Washington" "Washington"],
"sh:resultMessage" "values conformed to 2 of the following sh:xone shapes: [\"ex:one-part\" \"ex:two-parts\"]; must only conform to one"}]}}
(ex-data db2)))
(is (= "Subject ex:Named violates constraint sh:xone of shape ex:orShape - values conformed to 2 of the following sh:xone shapes: [\"ex:one-part\" \"ex:two-parts\"]; must only conform to one."
Expand Down

0 comments on commit bd83599

Please sign in to comment.