• Stars
    star
    219
  • Rank 181,133 (Top 4 %)
  • Language
    Java
  • Created over 14 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clojure's data structures modified for use outside of Clojure
This library has been extracted from the master branch of Clojure (http://clojure.org)

version 1.5.1 (as of October 2013)

http://github.com/richhickey/clojure

created by Rich Hickey. The core data structures and algorithms are due to him.
This library is distributed with the same license as the Clojure programming 
language itself (EPL, see file epl-v10.html).

It has been modified by Karl Krukow <[email protected]>, and mistakes introduced are mine.


Maven

<dependency>
  <groupId>com.github.krukow</groupId>
  <artifactId>clj-ds</artifactId>
  <version>0.0.4</version>
</dependency>


*WHY*
First, I love Clojure :) ... 
Unfortunately sometimes clients require that I use Java...

The data structures used in the Clojure programming language are a great
implementation of a number of useful persistent data structures 
(see e.g., the section on immutable data structures on
http://clojure.org/functional_programming). 

However, these data structures are tailor-made to work optimally in the
Clojure programming language, and while it is possible to use these from
Java (since Clojure is distributed as a .jar file), it is inconvenient
for a number of reasons (see below). Since it is (unfortunately) not always
possible to use Clojure, I've created this library to at least reap some of the
Clojure benefits in environments constrained to Java. 
Beyond Java, other JVM languages like Erjang, Scala, JRuby and Groovy may benefit
from immutability & persistence, and from this implementation.

*Advantages of clj-ds when constrained to working with Java*
Currently the Clojure data structures are implemented in Java. In the future,
all of Clojure will be implemented in Clojure itself (known as "Clojure-in-Clojure").
This has many advantages for Clojure, but when it happens the data structures will 
probably be even more intertwined with the rest of the language, 
and may be even more inconvenient to use in a Java context.

The clj-ds project will maintain Java versions of the code, and where possible attempt
to "port" improvements made in the Clojure versions back into clj-ds. Thus keeping maintained
versions of the Java data structures. 

In the current Clojure version, calling certain methods on PersistentHashMap requires
loading the entire Clojure runtime, including the bootstrap process. This takes about one second.
This means that the first time one of these methods is called, a Java user will experience a
slight delay (and a memory-usage increase). Further, many of the Clojure runtime 
Java classes are not needed when only support for persistent data structures 
is wanted (e.g., the compiler).

The clj-ds library is not dependent on the Clojure runtime nor does it run any
Clojure bootstrap process, e.g., the classes that deal with compilation have been removed. 
This results in a smaller library, and the mentioned delay does not occur.

Clojure is a dynamically typed language. Java is statically typed, and supports
'generics' from version 5. A Java user would expect generics support from a Java
data structure library, and the Clojure version doesn't have this. 
clj-ds will support generics.

Finally, a slight improvement. 
Certain of the Clojure data structure methods use Clojure's 'seq' abstraction
in the implementation of the Java 'iterator' pattern. It is possible, to make
slightly more efficient iterators using a tailor made iterator. clj-ds does this.

Example stats for iterating through various data structures:
(20-40% improvement, matters only for quite large structures)

PersistentHashSet:
----
500.000 elements
58 ms (Java avg.)
192 ms (Pure Clojure avg)
106 ms (clj-ds avg)
---
1 mio elements:
104 ms (Java avg.)
497 ms (Pure Clojure avg)
371 ms (clj-ds avg)

---
PersistentHashMap
---
500.000 elements
94 ms (Java avg.)
189 ms (Pure Clojure avg)
131 ms (clj-ds avg)

1 mio elements:
128 ms (Java avg.)
549 ms (Pure Clojure avg)
394 ms (clj-ds avg)

---
PersistentVector 
---
1 mio elements:
104 ms (Java avg.)
122 ms (Pure Clojure avg)
104 ms (clj-ds avg)

2 mio elements:
186 ms (Java avg.)
223 ms (Pure Clojure avg)
184 ms (clj-ds avg)

More Repositories

1

stomple

A robust full-featured Stomple client for JavaScript
Java
35
star
2

calabash-script

Use ClojureScript to write iOS functional tests
Clojure
20
star
3

clojure-circuit-breaker

Fast functional circuit-breaker written in Clojure
Clojure
14
star
4

ants-demo

adapted from rich hickeys original ants demo
7
star
5

edmondson

An extensible, easy-to-use toolkit for analyzing and scoring survey constructs like psychological safety and generative culture. Supports multiple survey-systems like Google Forms and Qualtrics.
Python
5
star
6

clojure-in-practice-example

Clojure
4
star
7

versionmanager

A JavaScript library that manages multiple changes made to the global object
JavaScript
3
star
8

calabash-jvm-example

Cucumber JVM + Calabash JVM Java Example
3
star
9

tribook

Sample application for blog posting on designing client/server web-applications
3
star
10

dart-contrib

This has been moved to: https://github.com/trifork/dlib
Java
3
star
11

vsts-hacks

Chrome extension for some convenience in VSTS for Visual Studio Mobile Center
Clojure
2
star
12

trie

A simple JavaScript implementation of the Trie datastructure
JavaScript
2
star
13

lux

(More than) A clojure wrapper for Lucene
Clojure
2
star
14

net.higherorder.specialize

A partial evaluator for JavaScript written in JavaScript
2
star
15

vsts-flow-metrics

Tool for visualizing flow metrics from Visual Studio Team Services data
Clojure
2
star
16

motion-calabash-inspect2013

Calabash-RubyMotion Sample from Inspect2013 conference
Ruby
2
star
17

uia-repl

A ClojureScript REPL for the UIAutomation JavaScript execution environment (kinda hacky)
JavaScript
1
star
18

swing-demo

example used in intro to clojure
Clojure
1
star
19

advanced_javascript_tooling

Example project for organizing larger scale JavaScript projects
JavaScript
1
star