Data structures & utilities for CLJ/CLJS


License
Apache-2.0

Documentation

thi.ng/dstruct

Contents

About the project

Description

This library provides the following data structures for Clojure/Clojurescript:

  • Bi-directional index / map
  • Heap
  • Interval tree
  • I/O stream abstractions
  • Unionfind (disjoint sets, connected components, undirected graph)

Furthermore, a number of general purpose helper functions for indexing, sequencing etc. is included.

This library is the result of a thi.ng projectwide restructuring / dissolving of the thi.ng/common library.

Note: This library relies on the new conditional reader syntax of recent Clojure & Clojurescript versions and therefore is not compatible with Clojure versions < 1.7.0

Leiningen coordinates

Latest stable

[thi.ng/dstruct "0.1.5"]

Namespaces

Tests

  • TBD

Project definition

Injected properties

0.2.1

Dependencies

Runtime

Clojure

[org.clojure/clojure "1.8.0"]

ClojureScript

[org.clojure/clojurescript "1.8.40"]

thi.ng/math

[thi.ng/math "0.2.1"]

thi.ng/xerror

[thi.ng/xerror "0.1.0"]

Development

Criterium

[criterium "0.4.4"]

clojurescript.test

[com.cemerick/clojurescript.test "0.3.3"]

Cljsbuild

[lein-cljsbuild "1.1.3"]

Building this project

This project is written in a literate programming format and requires Emacs & Org-mode to generate usable source code. Assuming both tools are installed, the easiest way to generate a working project is via command line (make sure emacs is on your path or else edit its path in tangle.sh):

git clone https://github.com/thi.ng/dstruct.git
cd dstruct
./tangle.sh src/*.org test/*.org

Tangling is the process of extracting & combining source blocks from .org files into an actual working project/source tree. Once tangling is complete, you can cd into the generated project directory (babel) and then use lein as usual.

Testing

The project.clj file defines an alias to trigger a complete build & tests for both CLJ & CLJS versions.

cd babel
lein cleantest

To build the Clojurescript version simply run lein cljsbuild test from the same directory. A small HTML harness for the resulting JS file is also located in that folder (babel/index.html), allowing for further experimentation in the browser.

Working with the REPL

Editing code blocks or files in Org-mode, then re-loading & testing changes is quite trivial. Simply launch a REPL (via lein or Emacs) as usual. Everytime you’ve made changes to an .org file, re-tangle it from Emacs (C-c C-v t) or tangle.sh, then reload the namespace in the REPL via (require 'thi.ng.dstruct... :reload) or similar.

Leiningen project file

(defproject thi.ng/dstruct "<<version>>"
  :description  "Data structures & utilities for CLJ/CLJS"
  :url          "<<project-url>>"
  :license      {:name "Apache Software License 2.0"
                 :url "http://www.apache.org/licenses/LICENSE-2.0"
                 :distribution :repo}
  :scm          {:name "git"
                 :url "git@github.com:thi-ng/dstruct.git"}

  :min-lein-vesion "2.4.0"

  :dependencies [<<dep-clj>>
                 <<dep-cljs>>
                 <<dep-math>>
                 <<dep-xerror>>]

  :source-paths ["src"]
  :test-paths   ["test"]

  :profiles     {:dev {:dependencies [<<dep-criterium>>]
                       :plugins [<<dep-cljsbuild>>
                                 <<dep-cljs-test>>]
                       :global-vars {*warn-on-reflection* true}
                       :jvm-opts ^:replace []
                       :aliases {"cleantest" ["do" "clean," "test," "cljsbuild" "test"]}}}

  :cljsbuild    {:builds [{:id "simple"
                           :source-paths ["src" "test"]
                           :compiler {:output-to "<<cljs-artefact-path>>"
                                      :optimizations :whitespace
                                      :parallel-build true
                                      :static-fns true
                                      :pretty-print true}}]
                 :test-commands {"unit-tests" ["phantomjs" :runner "<<cljs-artefact-path>>"]}}

  :pom-addition [:developers [:developer
                              [:name "Karsten Schmidt"]
                              [:url "http://postspectacular.com"]
                              [:timezone "0"]]])

ClojureScript HTML harness

<!DOCTYPE html>
<html lang="en">
  <head>
    <title><<lein-coords>> test</title>
  </head>
  <body>
    <script type="text/javascript" src="<<cljs-artefact-path>>"></script>
  </body>
</html>

Accessing library version during runtime

The autogenerated namespace thi.ng.dstruct.version contains a single symbol version holding the version string defined above:

(use '[thi.ng.dstruct.version])

(prn version)
;; "<<version>>"

Version namespace

Release history

Version Released Description
0.2.1 2016-06-13 bugfix CLJS InputStreamWrapper
0.2.0 2016-04-05 refactor IBuffer / IIntoBuffer protocol, minor other bugfixes
0.1.5 2016-03-19 update deps, minor fix streams ns
0.1.4 2016-03-19 fix tangling of tree walk fns
0.1.3 2016-03-19 add BidirIndex, minor refactor, update deps
0.1.2 2015-11-05 add clj/cljs i/o stream abstractions
0.1.1 2015-09-07 bugfix DisjointSet, updated dependencies
0.1.0 2015-05-25 initial test release

Contributors

Name Role Website
Karsten Schmidt initiator & principal developer http://postspectacular.com

I’ve got a fairly detailed roadmap and task list to implement over the coming months, but am always happy to receive feedback & suggestions and have issues filed. Once the core engine is more refined I’ll be gladly welcoming other contributions. Thanks for understanding!

License

This project is open source and licensed under the Apache Software License 2.0.