Skip to content

Commit

Permalink
identical-ints?
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Aug 23, 2024
1 parent b59094e commit ac6d8d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions java/com/ambrosebs/map/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ambrosebs.map;

public class Util {
public static boolean identicalInts(int x, int y) {
return x == y;
}
}
31 changes: 17 additions & 14 deletions src/com/ambrosebs/map.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
(defmacro bit-shift-left [x n]
`(clojure.lang.Numbers/shiftLeftInt ~x ~n))

(defmacro identical-ints? [x y]
`(com.ambrosebs.map.Util/identicalInts ~x ~y))

(defonce ^:private NOT-FOUND
(Object.))

Expand Down Expand Up @@ -161,7 +164,7 @@
([shift key1 val1 key2hash key2 val2]
(let [key1hash (core/hash key1)]
(cond
(== key1hash key2hash)
(identical-ints? key1hash key2hash)
(hash-collision-node-ctor
nil
key1hash
Expand Down Expand Up @@ -371,7 +374,7 @@
(inc (* 2 idx))
n))

(== bitmap bit)
(identical-ints? bitmap bit)
nil

:else
Expand All @@ -385,7 +388,7 @@
idx))))

(= key key-or-null)
(if (== bitmap bit)
(if (identical-ints? bitmap bit)
nil
(bitmap-indexed-node-ctor
nil
Expand Down Expand Up @@ -507,7 +510,7 @@

EditAndRemovePair
(edit-and-remove-pair [this edit bit i]
(if (== bitmap bit)
(if (identical-ints? bitmap bit)
nil
(let [^BitmapIndexedNode editable
(ensure-editable this edit)
Expand Down Expand Up @@ -745,7 +748,7 @@
(inc (* 2 idx))
n)

(== bitmap bit)
(identical-ints? bitmap bit)
nil

:else
Expand Down Expand Up @@ -793,10 +796,10 @@
[this shift hash key val added-leaf]
(let [^Box added-leaf added-leaf]
;(prn "HashCollisionNode assoc-node")
(if (== hash (.-hash this))
(if (identical-ints? hash (.-hash this))
(let [idx (find-index array count key)]
(cond
(not= -1 idx)
(not (identical-ints? -1 idx))
(if (identical? val (aget array (inc idx)))
this
(hash-collision-node-ctor
Expand Down Expand Up @@ -836,10 +839,10 @@
(without-node [this shift hash key]
(let [idx (find-index array count key)]
(cond
(== -1 idx)
(identical-ints? -1 idx)
this

(== 1 count)
(identical-ints? 1 count)
nil

:else
Expand Down Expand Up @@ -914,10 +917,10 @@

(assoc-node [this edit shift hash key val added-leaf]
(let [^Box added-leaf added-leaf]
(if (== hash (.-hash this))
(if (identical-ints? hash (.-hash this))
(let [idx (find-index array count key)]
(cond
(not (== idx -1))
(not (identical-ints? idx -1))
(if (identical? (aget array (inc idx))
val)
this
Expand Down Expand Up @@ -966,10 +969,10 @@
(without-node [this edit shift hash key removed-leaf]
(let [^Box removed-leaf removed-leaf
idx (find-index array count key)]
(if (== -1 idx)
(if (identical-ints? -1 idx)
this
(let [_ (set! (.-val removed-leaf) removed-leaf)]
(if (== 1 count)
(if (identical-ints? 1 count)
nil
(let [^HashCollisionNode
editable
Expand Down Expand Up @@ -1467,7 +1470,7 @@
(empty? tasks)
(combinef)

(== 1 (count tasks))
(identical-ints? 1 (count tasks))
((nth tasks 0))

:else
Expand Down

0 comments on commit ac6d8d9

Please sign in to comment.