Skip to content

Commit

Permalink
Release 0.9.0-beta20
Browse files Browse the repository at this point in the history
  • Loading branch information
luposlip committed Jan 6, 2025
1 parent 8204178 commit 2b59b79
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 27 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ All notable changes to this project will be documented in this file. This change
- Timestamps for historical versions
- Optimize (speed+size of) low level index format

## [0.9.0-beta20] - 2025-01-06

"Happy New Year"-release!

### Enhanced

- Throwing a sane error, when opening an EMPTY database!

## [0.9.0-beta19] - 2024-10-25

Support `nippy` based files in a `zip` based database - called `zippy`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# nd-db

```clojure
[com.luposlip/nd-db "0.9.0-beta19"]
[com.luposlip/nd-db "0.9.0-beta20"]
```

_Newline Delimited (read-only) Databases!_
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.luposlip/nd-db "0.9.0-beta19"
(defproject com.luposlip/nd-db "0.9.0-beta20"
:description "Clojure library to use newline delimited files as fast read-only databases."
:url "https://github.com/luposlip/nd-db"
:license {:name "Apache License, Version 2.0"
Expand Down
Empty file added resources/test/empty.ndnippy
Empty file.
52 changes: 28 additions & 24 deletions src/nd_db/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,34 @@
;; without parallelization: 18s
;; with: 6s (partition size 2048, fold size 32
;; that's around 2/3 less processing time
(let [[fline & rlines] (line-seq rdr)
[lines init-offset] (if skip-first?
[rlines (inc (count (.getBytes ^String fline)))]
[(cons fline rlines) 0])]
(with-meta
(->> lines
(partition-all 2048)
(reduce
(fn [[offset _ :as acc] part]
(let [res (->> part
(into [])
(r/fold 32
idx-combinr
(idx-reducr id-fn)))
[s l] (->> res peek rest)]
(-> acc
(update 0 #(+ 1 % s l))
(update 1 merge (reduce
(fn [a [id s l]]
(assoc a id [(+ offset s) l]))
{} res)))))
[init-offset {}])
second)
{:as-of (Instant/now)}))))
(let [[fline & rlines :as all-lines] (line-seq rdr) ]
(if all-lines
(let [[lines init-offset] (if skip-first?
[rlines (inc (count (.getBytes ^String fline)))]
[(cons fline rlines) 0])]
(with-meta
(->> lines
(partition-all 2048)
(reduce
(fn [[offset _ :as acc] part]
(let [res (->> part
(into [])
(r/fold 32
idx-combinr
(idx-reducr id-fn)))
[s l] (->> res peek rest)]
(-> acc
(update 0 #(+ 1 % s l))
(update 1 merge (reduce
(fn [a [id s l]]
(assoc a id [(+ offset s) l]))
{} res)))))
[init-offset {}])
second)
{:as-of (Instant/now)}))
(throw (ex-info "Cannot use empty database!" {:filename filename
:id-fn? (ifn? id-fn)
:skip-first? skip-first?}))))))

(defn reader
"Returns a BufferedReader of the database index.
Expand Down
9 changes: 8 additions & 1 deletion test/nd_db/index_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[nd-db
[core :as nddb]
[index :as sut]]
[nd-db.util :as ndut]))
[nd-db.util :as ndut])
(:import clojure.lang.ExceptionInfo))

(def by-id #(Integer. ^String (second (re-find #"^\{\"id\":(\d+)" %))))

Expand Down Expand Up @@ -50,3 +51,9 @@
new-index-keys (-> new-db :index deref keys set)]
(is (ndut/db? new-db))
(is (= new-id (new-index-keys new-id)))))

(deftest empty-db
(is (thrown?
ExceptionInfo
(nddb/db :filename "resources/test/empty.ndnippy"
:id-path :id))))

0 comments on commit 2b59b79

Please sign in to comment.