Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikea/concrete
Fully persistent data structures in Java
https://github.com/mikea/concrete
Last synced: 3 months ago
JSON representation
Fully persistent data structures in Java
- Host: GitHub
- URL: https://github.com/mikea/concrete
- Owner: mikea
- License: apache-2.0
- Created: 2012-05-04T18:37:26.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-11-14T06:34:59.000Z (about 8 years ago)
- Last Synced: 2023-04-11T10:47:33.533Z (almost 2 years ago)
- Language: Java
- Homepage:
- Size: 147 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Concrete
> [Fully persistent](https://en.wikipedia.org/wiki/Persistent_data_structure) data structures in Java.[![CircleCI](https://img.shields.io/circleci/project/mikea/concrete.svg?style=flat)](https://circleci.com/gh/mikea/concrete)
Implementation follows "Purely Functional Data Structures" by Chris Okasaki unless said otherwise.
## PStack
O(1) operations: pushFront, peekFront, popFront, size, isEmpty.
O(N) operations: reverse.```java
PStack stack = PStack.newStack();
stack = stack.pushFront("a");
assertEquals("a", stack.peekFront());
stack = stack.popFront();
assertTrue(stack.isEmpty());
```PStack runtime performance is always better than ArrayList and LinkedList (ignoring GC overhead):
[benchmark report](https://microbenchmarks.appspot.com/runs/eba86353-07d3-4db3-87e5-875ec5d373eb#r:scenario.benchmarkSpec.parameters.implementation&c:scenario.benchmarkSpec.parameters.test,scenario.benchmarkSpec.parameters.length),
[code](https://github.com/mikea/concrete/blob/master/src/test/java/com/mikea/concrete/benchmarks/StackBenchmark.java).Stacks support constant append operation:
```java
PStack stack1 = PStack.newStack("a", "b");
PStack stack2 = PStack.newStack("c", "d");
assertEquals("[a, b, c, d]", stack1.append(stack2).toString());
```## PQueue
O(1) operations: pushBack, popFront, peekFront, size, isEmpty
Queue with [amortized](https://en.wikipedia.org/wiki/Amortized_analysis) O(1) performance:
```java
PQueue queue = PQueue.newAmortizedQueue();
queue = queue.pushBack("a");
queue = queue.pushBackAll("b", "c");
assertEquals("a", queue.peekFront());
queue = queue.popFront();
assertEquals("b", queue.peekFront());
queue = queue.popFront();
assertEquals("[c]", queue.toString());
```
Realtime queue with guaranteed O(1) performance:```java
PQueue queue = PQueue.newRealtimeQueue();
queue = queue.pushBack("a");
queue = queue.pushBackAll("b", "c");
assertEquals("a", queue.peekFront());
queue = queue.popFront();
assertEquals("b", queue.peekFront());
queue = queue.popFront();
assertEquals("[c]", queue.toString());
```## PDeque
O(1) operations: pushFront, popFront, peekFront, pushBack, peekBack, peekFront, size, isEmpty.
Deque with [amortized](https://en.wikipedia.org/wiki/Amortized_analysis) O(1) performance:
```java
PDeque deque = PDeque.newAmortizedDeque();
deque = deque.pushBackAll("b", "c");
deque = deque.pushFront("a");
deque = deque.popBack();
assertEquals("[a, b]", deque.toString());
```## PArray
Random-access array.
O(log N) operations: pushFront, popFront, peekFront, set, get.
```java
PArray array = PArray.newBinaryArray();
array = array.pushFrontAll("a", "b", "c");
assertEquals("b", array.get(1));
array = array.set(1, "X");
assertEquals("[a, X, c]", array.toString());
```### Base Classes
- PIterable with O(1) operations: popFront, peekFront, isEmpty.
- PCollection with O(1) operations: isEmpty, clear, size.