Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/xitdb/array_list.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@

clojure.lang.Indexed
(nth [_ i]
(let [cursor (.getCursor ral (long i))]
(common/-read-from-cursor cursor)))
(let [count (.count ral)
idx (long i)]
(if (and (>= idx 0) (< idx count))
(common/-read-from-cursor (.getCursor ral idx))
(throw (IndexOutOfBoundsException. (str "Index: " i ", Size: " count))))))

(nth [_ i not-found]
(let [cursor (.getCursor ral (long i))]
Expand Down
2 changes: 1 addition & 1 deletion src/xitdb/util/operations.clj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
cursor (.getCursor rhs hash-code)]
(some? cursor)))

(defn ^WriteHashMap set-empty!
(defn ^WriteHashSet set-empty!
"Replaces the whs value with an empty set."
[^WriteHashSet whs]
(let [empty-set (conversion/v->slot! (.cursor whs) #{})]
Expand Down
5 changes: 4 additions & 1 deletion test/xitdb/cursor_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
(swap! cursor1 assoc-in [3 :hidden] :changed-by-swap!)
(is (= [1 2 3 {:hidden :changed-by-swap!} 5]) (xdb/materialize @cursor1))
(is (= :changed-by-swap! @cursor3))
(is (= 3 @cursor2))))))
(is (= 3 @cursor2)))

(testing "Correctly handles invalid cursor path"
(is (thrown? IndexOutOfBoundsException @(xdb/xdb-cursor db [:foo :bar 999])))))))