Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PersistentVector, transients, polishing #7

Open
wants to merge 295 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
295 commits
Select commit Hold shift + click to select a range
025c1ea
renamed __ownerID to _owner
Aug 29, 2014
984c677
Merge branch 'transientMap' into vector
Aug 29, 2014
4fceff4
factor Owner to persistent.dart, use Owner from there in Vector, remo…
Aug 29, 2014
7610122
Extracted ReadMap interface
syslo Aug 29, 2014
f8f5a65
rename all occurrences of mutable to transient
Aug 29, 2014
759a77a
Merge branch 'transientMap' of github.com:vacuumlabs/persistent into …
syslo Aug 29, 2014
1994973
Refactor test.
brandys11 Aug 29, 2014
63fabc5
map implements Persistent
brandys11 Aug 29, 2014
4210b72
new randomized test for vector
Aug 29, 2014
e108488
merge
brandys11 Aug 29, 2014
e2d3949
Repair merge
brandys11 Aug 29, 2014
00219a6
Repair merge
brandys11 Aug 29, 2014
166dd5e
Extracted ReadSet, created TransientSet, Initial Transient Set implem…
syslo Aug 29, 2014
bac07c7
remove unused code
Aug 29, 2014
e3934ae
fix typo and remove another piece of unused code
Aug 29, 2014
896bdf5
add containsKey
brandys11 Aug 29, 2014
1b3b9ff
Merge remote-tracking branch 'origin/transientMap' into vector
tomaskulich Aug 29, 2014
aa7a5f2
remove unused code
Aug 29, 2014
923383c
Merge branch 'vector' of github.com:vacuumlabs/persistent into vector
tomaskulich Aug 30, 2014
54b3098
Merge pull request #3 from vacuumlabs/transientMap
tomaskulich Aug 30, 2014
f9dbea0
Merge pull request #5 from vacuumlabs/newData
tomaskulich Aug 30, 2014
697f11e
Merge pull request #2 from vacuumlabs/vector
tomaskulich Aug 30, 2014
e0b2de4
Merge remote-tracking branch 'origin/transientMap'
tomaskulich Aug 30, 2014
3005cea
refactoring tests, cought few bugs
tomaskulich Sep 1, 2014
a3ff118
Merge remote-tracking branch 'origin/master' into documentation
syslo Sep 2, 2014
bc5b376
extract read interface to common class in persistent and transientmap
brandys11 Sep 2, 2014
1652c87
Decrease number of operations in map_test
brandys11 Sep 2, 2014
3a9fc3a
Remove poluxs tests and add adjust to randomized_test
brandys11 Sep 2, 2014
10bdd30
Merge remote-tracking branch 'origin/master' into benchmark
syslo Sep 2, 2014
a80b171
Deterministic tests
brandys11 Sep 2, 2014
e897296
Memory bench: Linear interpolation replaced by single run ignoring VM…
syslo Sep 2, 2014
a859a79
Merge remote-tracking branch 'origin/master' into transientSet
syslo Sep 2, 2014
996da86
fix vector bug when creating new root
Sep 2, 2014
b7b752a
Merge pull request #8 from vacuumlabs/polishing
tomaskulich Sep 2, 2014
fba6905
assertDeeplyEquals made simpler
tomaskulich Sep 2, 2014
16df79c
Merge pull request #14 from vacuumlabs/vector_fix
tomaskulich Sep 2, 2014
72cfbf9
Merge remote-tracking branch 'origin/benchmark'
tomaskulich Sep 2, 2014
3c0a0a7
Add tests I have forgotten
brandys11 Sep 2, 2014
f634d92
randomlyChangeImpl implemented for vector
Sep 2, 2014
29eeb08
test for equality and hashcode
Sep 2, 2014
4e2ecd2
Updated set interface and transient tests added
syslo Sep 2, 2014
a4de7a5
Merge remote-tracking branch 'origin/master' into transientSet
syslo Sep 2, 2014
93c2a38
Updated original test with delete(safe), standardized filenames, read…
syslo Sep 2, 2014
7d3e14f
Merge remote-tracking branch 'origin/master' into benchmark
syslo Sep 2, 2014
f72a7c8
MapBench: lookup: fixed orElse as positional
syslo Sep 2, 2014
755689b
Simplified Map memory benchmark
syslo Sep 2, 2014
fbf706e
Map bench: Removed unused Option occurence
syslo Sep 2, 2014
669970f
polishing the test
tomaskulich Sep 2, 2014
6e8cdc1
Simplified Set tests
syslo Sep 2, 2014
279d44c
faster iterator + fixed found bugs
Sep 2, 2014
473f285
removed pubspec.lock
Sep 2, 2014
2595fa2
changed hashcode computation in vector to use hashObjects from quiver
Sep 2, 2014
c1dfc32
renaming, polishing makefile
tomaskulich Sep 2, 2014
40f6b4a
Merge branch 'master' into benchmark
tomaskulich Sep 2, 2014
42e1c32
Merge remote-tracking branch 'origin/master' into benchmark
tomaskulich Sep 2, 2014
8c2ae4f
Map speed benchmark makefile
syslo Sep 3, 2014
01351d6
Merge remote-tracking branch 'origin/master' into documentation
syslo Sep 3, 2014
b828c8f
ReadMap documentation
syslo Sep 3, 2014
e559bdc
Merge pull request #16 from vacuumlabs/transientSet
tomaskulich Sep 3, 2014
ba3c223
quiver dependency made less strict
tomaskulich Sep 3, 2014
a6d5be6
Merge pull request #19 from vacuumlabs/vector_quiver_hashcode
tomaskulich Sep 3, 2014
779dea5
Merge pull request #15 from vacuumlabs/vector_test
tomaskulich Sep 3, 2014
a81dcb8
Merge remote-tracking branch 'origin/master' into benchmark
tomaskulich Sep 3, 2014
87bfec5
Splitted ReadMap#mapValues to Persistent and Transient map
syslo Sep 3, 2014
4942f1d
Deleted ReadMap signature adjustment
syslo Sep 3, 2014
ba9f937
Revert "Merge remote-tracking branch 'origin/cache' into documentation"
syslo Sep 3, 2014
2679520
Merge remote-tracking branch 'origin/master' into documentation
syslo Sep 3, 2014
d9af913
Removed "part" directive for set_model
syslo Sep 3, 2014
f5b4bf9
Merge remote-tracking branch 'origin/master' into documentation
syslo Sep 3, 2014
030e166
ReadVector documentation
syslo Sep 3, 2014
72dc31b
Make deep functions global
brandys11 Sep 3, 2014
390956e
small changes in benchmark, makefile
tomaskulich Sep 3, 2014
dad9bab
Merge pull request #13 from vacuumlabs/benchmark
tomaskulich Sep 3, 2014
030d5bf
Set documentation
syslo Sep 3, 2014
3d57d3f
Documented "safe".
syslo Sep 3, 2014
17821a5
fixes
brandys11 Sep 3, 2014
4e46d7d
persistent vector
brandys11 Sep 3, 2014
9ebbdc3
Merge branch 'master' of github.com:vacuumlabs/persistent into deep
brandys11 Sep 3, 2014
9bc79e3
Merge branch 'vector_iterator' of github.com:vacuumlabs/persistent in…
brandys11 Sep 3, 2014
757e28d
fix typo
Sep 3, 2014
b9bab40
fix adding nulls to vector, random test will test it now too
Sep 3, 2014
bb394df
Merge pull request #21 from vacuumlabs/fix_map_interface
tomaskulich Sep 3, 2014
88fac27
Started new README
syslo Sep 3, 2014
3df9d98
Sets: asTransient and asPersistent moved
syslo Sep 3, 2014
9e85d6e
Moved mass operation actions from ReadSet to PersistentSet
syslo Sep 3, 2014
da83664
got rid of test/src/ folder
Sep 3, 2014
8ba92b1
created deterministic test for nulls
Sep 3, 2014
5452a36
Moved mass operation actions from ReadMap to PersistentMap
syslo Sep 3, 2014
a8c3f6b
Fixed asTransient / asPersistent stuff in set tests
syslo Sep 3, 2014
c34754a
Merge pull request #25 from vacuumlabs/remove_vector_model
tomaskulich Sep 3, 2014
8ec44e0
Merge pull request #24 from vacuumlabs/vector_fixnull
tomaskulich Sep 3, 2014
b92c75e
Merge
brandys11 Sep 3, 2014
5d1c50b
Merge remote-tracking branch 'origin/vector_fixnull' into deep
brandys11 Sep 3, 2014
d460faf
Remove print
brandys11 Sep 4, 2014
aac31e7
Merge branch 'master' of github.com:vacuumlabs/persistent into deep
brandys11 Sep 4, 2014
0e39d85
Fix hashing, do not use bigint
brandys11 Sep 4, 2014
ef9fc2b
PersistentSet#cartesianProduct now returns iterable
syslo Sep 4, 2014
ecefffd
Set#filter added to PersistentSet interface and returns lazy iterable
syslo Sep 4, 2014
e81be52
Set.delete safe revived and documented
syslo Sep 4, 2014
b87309c
Removed filter - just alias for where
syslo Sep 4, 2014
8dc9a0d
README: completed Design section
syslo Sep 4, 2014
6b61bf7
Merge branch 'master' into documentation
syslo Sep 4, 2014
aa3a74c
Merge remote-tracking branch 'origin/master' into documentation
syslo Sep 4, 2014
0f831d4
Added example
syslo Sep 4, 2014
98ccae7
Merge pull request #26 from vacuumlabs/strict_transient
tomaskulich Sep 4, 2014
569c8bc
Merge pull request #27 from vacuumlabs/deep
tomaskulich Sep 4, 2014
ab999b2
Merge pull request #18 from vacuumlabs/vector_iterator
tomaskulich Sep 4, 2014
d593894
Merge remote-tracking branch 'origin/master' into documentation
syslo Sep 4, 2014
c9c13a5
Benchmark vector speed
syslo Sep 4, 2014
3685942
Renamed vector_speed library
syslo Sep 4, 2014
1a295eb
Benchmark vector memory
syslo Sep 4, 2014
8d20228
Fixed showing errors in map mem bench
syslo Sep 4, 2014
275f432
Set operations are indepenednt on implementation.
syslo Sep 4, 2014
97ffb3a
Merge pull request #29 from vacuumlabs/benchmark
tomaskulich Sep 4, 2014
e613353
Merge pull request #28 from vacuumlabs/documentation
tomaskulich Sep 4, 2014
613dac7
Splitted speed benchmarks to Read/Write
syslo Sep 5, 2014
0eda354
Updated license
syslo Sep 5, 2014
c028827
Merge pull request #36 from vacuumlabs/license
tomaskulich Sep 5, 2014
294101a
Fixed 'Vaccum' typo
syslo Sep 5, 2014
ba32030
Merge pull request #37 from vacuumlabs/license
syslo Sep 5, 2014
23a7cca
Grouped Read/Write benchmarks
syslo Sep 5, 2014
469c55e
Benchmark compilation to 'build' directory
syslo Sep 5, 2014
f834c82
Map union/intersection no longer needs PersistentMapImpl
syslo Sep 5, 2014
8581b62
Map union/intersection tests
syslo Sep 5, 2014
6b6c0a7
Structured tests, all tests runner
syslo Sep 5, 2014
e31652d
Merge remote-tracking branch 'origin/master' into fix_union_intersect
syslo Sep 5, 2014
c99623f
Moved PersistentVector#iterator implementation
syslo Sep 5, 2014
25358bd
Merge pull request #39 from vacuumlabs/quick_fix_vector_iter_impl
syslo Sep 5, 2014
e881c03
Merge remote-tracking branch 'origin/master' into benchmark
syslo Sep 5, 2014
c84835e
Merge pull request #38 from vacuumlabs/fix_union_intersect
tomaskulich Sep 11, 2014
9ba2dc1
Merge pull request #35 from vacuumlabs/benchmark
tomaskulich Sep 11, 2014
4c6412a
Merge remote-tracking branch 'origin/master' into tests
syslo Sep 16, 2014
c5cf203
No msgs when running all tests
syslo Sep 16, 2014
d154626
Moved basic tests to map tests
syslo Sep 16, 2014
bc46673
Map test in unittest interface
syslo Sep 16, 2014
cdb5d28
LinkedList documentation
syslo Sep 16, 2014
fc1939c
Immutable safety to Linked Lists
syslo Sep 16, 2014
08dd931
LinkedList tests
syslo Sep 16, 2014
cb80448
Removed task scripts - benchmarks have their makefiles and tests have…
syslo Sep 16, 2014
5f9ec4b
Vector tests
syslo Sep 16, 2014
da917a1
Privatized members
syslo Sep 17, 2014
8be3cee
Documented persistent
syslo Sep 17, 2014
19431bb
Restrucured code
syslo Sep 17, 2014
7d942dc
Added drone.io Badge
syslo Sep 17, 2014
daa397e
Merge pull request #42 from vacuumlabs/api
tomaskulich Sep 22, 2014
4f8f4b1
new radme created, original readme moved to 'advanced' section
tomaskulich Sep 23, 2014
da630eb
renamed deepPersistent -> persist
tomaskulich Sep 23, 2014
9043cb8
Merge remote-tracking branch 'origin/master' into tests
syslo Sep 25, 2014
dfa0bce
Merge pull request #40 from vacuumlabs/tests
syslo Sep 25, 2014
b32191a
Merge remote-tracking branch 'origin/master' into LinkedList
syslo Sep 25, 2014
32da21f
Added linked list tests to all
syslo Sep 25, 2014
c9f9679
LL: Normalized hashing, efficient comparation
syslo Sep 25, 2014
7ed2c33
Merge pull request #41 from vacuumlabs/LinkedList
tomaskulich Sep 26, 2014
1aca464
renamed to vacuum_persistent
tomaskulich Sep 30, 2014
31a2011
polishing
tomaskulich Oct 1, 2014
2f0c660
in progress
tomaskulich Oct 2, 2014
d982e7a
some renaming
jurom Oct 2, 2014
7a09c35
fixed equality operators
jurom Oct 2, 2014
150aeb3
initial commit
matystl Oct 2, 2014
0194c3b
many many changes made to API, untested
jurom Oct 3, 2014
189c753
test
jurom Oct 3, 2014
3c3ca2a
coments for most of functions
matystl Oct 3, 2014
c516afd
all tests passed
jurom Oct 3, 2014
1ebee0f
Documentation checked, code repetition removed..
jurom Oct 6, 2014
6ef3148
some documentation checked
jurom Oct 6, 2014
c8d27ea
more documentation, merging
jurom Oct 6, 2014
0f9f630
Fix notfound
jurom Oct 6, 2014
056d0c7
more fixes
jurom Oct 6, 2014
fffa403
fixed tests, docs
jurom Oct 6, 2014
4334ff6
polishing
matystl Oct 7, 2014
3c99d37
fixed examples
matystl Oct 7, 2014
d0f6e20
global update
matystl Oct 7, 2014
a2ef73e
cursors and ref created
matystl Oct 7, 2014
46af0a1
Merge pull request #45 from vacuumlabs/polishing
tomaskulich Oct 7, 2014
42c5da9
Change interface to reference
matystl Oct 9, 2014
a2969f4
Merge pull request #47 from vacuumlabs/cursors
matystl Oct 9, 2014
2287a41
rename allowMissing to missingOk
matystl Oct 9, 2014
bce3db3
remove unecesary
matystl Oct 9, 2014
0a36b15
added new line to cursor.dart
matystl Oct 20, 2014
8032aad
rename Persistent to PersistentCollection
matystl Oct 20, 2014
ef6a3d2
added PersistentIndexedCollection
matystl Oct 20, 2014
a89a95b
dissoc on sets and vectors
matystl Oct 20, 2014
a5b4234
reduce description added
matystl Oct 20, 2014
460cedf
new line on test/all
matystl Oct 20, 2014
d534a05
new line on test/cursor
matystl Oct 20, 2014
660b1b1
new line on test
matystl Oct 20, 2014
ddcc371
Merge pull request #44 from vacuumlabs/moriFunc
hleumas Oct 26, 2014
31e576c
removing _isLeaf field, replaced by (? is _Leaf)
tomaskulich Dec 15, 2014
b3c0d55
merging nodebases
tomaskulich Dec 16, 2014
e9eb9ae
renamed few internals of map_impl
tomaskulich Dec 19, 2014
c973761
fixing benchmarks
tomaskulich Dec 19, 2014
b73dbfb
Merge branch 'fixing-benchmarks' into polishing
tomaskulich Dec 19, 2014
3c90688
renaming map internals
tomaskulich Dec 19, 2014
d5889c1
Merge branch 'renaming' into fixing-benchmarks
tomaskulich Dec 19, 2014
8febc0e
minor polish in memory benchmarks
tomaskulich Dec 20, 2014
61f8966
minor polish
tomaskulich Dec 23, 2014
210a633
Mori and vanilla js memory benchmark added
tomaskulich Dec 23, 2014
abe8621
gitignoring 'local' files in test
tomaskulich Dec 23, 2014
c4b0525
in progress
tomaskulich Dec 23, 2014
825b302
in progress
tomaskulich Dec 24, 2014
882b630
before generalising branching
tomaskulich Dec 25, 2014
38756c2
generalized branching factor
tomaskulich Dec 30, 2014
563e2b7
popcount removed succesfully
tomaskulich Dec 30, 2014
46c8b4b
in progress
tomaskulich Dec 31, 2014
9176a7c
preparing hash elimination
tomaskulich Dec 31, 2014
574b6df
map speed benchmark refactored
tomaskulich Jan 1, 2015
dc6eddc
Merge branch 'optimisation' into pokus-allocate-all
tomaskulich Jan 1, 2015
553ed0a
minor polishing
tomaskulich Jan 1, 2015
6a6c04c
Merge pull request #51 from vacuumlabs/removing-is-leaf
syslo Jan 2, 2015
4b05235
Merge pull request #53 from vacuumlabs/merging-nodebases
syslo Jan 2, 2015
374b4b6
Merge pull request #59 from vacuumlabs/renaming
syslo Jan 2, 2015
7104d0f
Merge pull request #60 from vacuumlabs/fixing-benchmarks
syslo Jan 2, 2015
0c1a4cd
Merge branch 'master' into benchmark-polishing
syslo Jan 2, 2015
66aa920
Merge remote-tracking branch 'origin/master' into benchmark-polishing
syslo Jan 2, 2015
384c28c
Merge pull request #61 from vacuumlabs/benchmark-polishing
syslo Jan 2, 2015
f6b716a
done
tomaskulich Jan 3, 2015
206a691
in progress
tomaskulich Jan 3, 2015
87c107f
tests running
tomaskulich Jan 3, 2015
d2014c7
in progress
tomaskulich Jan 3, 2015
20aa997
almost done
tomaskulich Jan 3, 2015
89e3519
preparing reverse hash
tomaskulich Jan 4, 2015
d345c41
reverse hash done
tomaskulich Jan 4, 2015
8542864
reverse hash opmtimised
tomaskulich Jan 4, 2015
96d3aa4
xored hash, hash bug fixed
tomaskulich Jan 5, 2015
9427927
speed benchmark uses numbers as keys
tomaskulich Jan 7, 2015
7aa6802
consuming more memory while doing read-benchmark
tomaskulich Jan 7, 2015
0aed7da
different sizes for benchmarking read and write
tomaskulich Jan 8, 2015
e98f5c7
Added mori speed benchmark
syslo Jan 8, 2015
96cf399
Merge branch 'optimisation' of github.com:vacuumlabs/persistent into …
syslo Jan 8, 2015
607b916
Bugfixed and synchronized mori speed bench with map
syslo Jan 8, 2015
5152229
Implemented Union and Intersect
syslo Jan 12, 2015
c776d8d
Fixed equality on hash colision
syslo Jan 23, 2015
ae1734b
Tests for union and intersect
syslo Jan 23, 2015
74c7a94
Fixed argument order bugs in intersection & union
syslo Jan 23, 2015
d0a2ade
All tests running
syslo Jan 23, 2015
ba00027
hashCodeModulo introduced to allow simmulate hash conflicts when testing
tomaskulich Jan 23, 2015
4b332fc
polish
tomaskulich Jan 23, 2015
f357564
delete dead code
tomaskulich Jan 23, 2015
0e1e5da
big renaming
tomaskulich Jan 23, 2015
42911b5
Merge branch 'optimisation'
tomaskulich Jan 23, 2015
aff538a
2.0 link added to readme
tomaskulich Jan 23, 2015
61bbe24
mori benchmark corrected and adjusted to mori 0.3
tomaskulich Jan 31, 2015
d6eff70
10fold error in benchmark harness corrected
tomaskulich Jan 31, 2015
da9bf67
example adjusted to 2.0 syntax
tomaskulich Jan 31, 2015
1f4adb6
inteligent .from constructor added
tomaskulich Jan 31, 2015
dacdfbc
set == now compares transients as it should i.e. by reference
tomaskulich Jan 31, 2015
5925aad
very simple benchmark added; just to bypass benchmark harness
tomaskulich Jan 31, 2015
c253b67
2.0 version!
tomaskulich Jan 31, 2015
9972c6e
_reverseHash renamed to _mangleHash: it was no propper reverse :)
tomaskulich May 20, 2015
760fe17
documentation polished, technical documentation added
tomaskulich May 20, 2015
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
.idea
packages
.project
local_pubspec_yaml
pubspec.lock
.idea
*.swp
build
7 changes: 7 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Paul Brauner <[email protected]>
Rafael Brandão <[email protected]>
Jozef Brandys <[email protected]>
Roman Hudec <[email protected]>
Marian Hornak <[email protected]>
Tomas Kulich <[email protected]>
Matus Fedak <[email protected]>
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Copyright 2014, VacuumLabs.
Copyright 2012, Google Inc. All rights reserved. Redistribution and
use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
Expand Down
96 changes: 61 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,76 @@
# Efficient Persistent Data Structures

[![Build Status](https://drone.io/github.com/polux/persistent/status.png)](https://drone.io/github.com/polux/persistent/latest)
[![Build Status](https://drone.io/github.com/vacuumlabs/persistent/status.png)](https://drone.io/github.com/vacuumlabs/persistent/latest)

Mostly efficient persistent maps and sets for now. Also option types.
Check out [changes in 2.0 version!] (changes_2_0.md)

"Persistent" means immutable here, not "saved on disk".
Learn how you can use [transients] (transients.md)

```dart
import 'package:persistent/persistent.dart';
Want to understand the code? Want to contribute? See [technical overview] (technical.md)

main() {
final emptyMap = new PersistentMap<String,int>();
final m1 = emptyMap.insert('a', 1).insert('b', 2);
final m2 = new PersistentMap<String,int>.fromMap({'a': 3, 'c': 4});
<!-- The project is forked from
[polux/persistent](https://github.com/polux/persistent).
-->

print(m1); // {a: 1, b: 2}
print(m2); // {c: 4, a: 3}
print(m1.lookup('a')); // Option.some(1)
print(m1.lookup('c')); // Option.none()
## What are persistent data structures
*Persistent* data structure is an immutable structure; the main difference with standard data structures is how you 'write' to them: instead of mutating
the old structure, you create the new, independent, (slightly) modified copy of it. Typical examples of commonly used Persistent structures are String (in Java, Javascript, Python, Ruby) or Python's Tuple or Java's BigDecimal. [(Not only)](http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey) we believe such concept could be beneficial also for other data structures such as Maps, Lists/Vectors, Sets.

final m3 = m1.delete('a');
print(m1); // {a: 1, b: 2}
print(m3); // {b: 2}
var couple = new PMap.fromMap({'father': 'Homer', 'mother': 'Marge'});
// do not (and can not) modify couple anymore
var withChild = couple.assoc('boy', 'Bart');
print(couple); // {mother: Marge, father: Homer}
print(withChild); // {boy: Bart, mother: Marge, father: Homer}

final m4 = m1.union(m2, (n,m) => n + m);
print(m4); // {c: 4, a: 4, b: 2}
## Got it. And it is cool because...?

final m5 = m1.mapValues((n) => n + 1);
print(m5); // {a: 2, b: 3}
### It disallows unwanted side effects
You know the story. Late in the evening, exhausted and frustrated you find out that some guy that implemented

final m6 = m1.adjust('a', (n) => n + 1);
print(m6); // {a: 2, b: 2}
}
```
int ComputeResponseLength(Map responseMap)

## Try it!
got a 'great' idea, that instead of just computing response length he also mutates responseMap in some tricky way (say, he does some kind of sanitization of responseMap). Even if this was mentioned in the documentation and even if the methods name was different: this is a spaghetti code.

```
git clone https://github.com/polux/persistent.git
cd persistent
pub install
dart example/map_example.dart
dart example/set_example.dart
dart test/map_bench.dart
```
### Equality and hashCode done right
Finally, they work as you'd expect. How cool is this:

## More
// deeply persist the structure of Maps and Lists
PMap a = persist({[1,2]: 'tower', [1,3]: 'water'});
PMap b = persist({[1,2]: 'tower', [1,3]: 'water'});
assert(a==b);
// kids, don't try this with standard List, it ain't going to work
print(a[persist([1, 2])]); // prints 'tower'

### Instant 'deep copy'
Just copy/pass the reference. It's like doing deep copy in O(1).

### Caching made easier
Caching can speed things up significantly. But how do you cache results of a function

List findSuspiciousEntries(List<Map> entries)

One possible workaround would be to JSONize entries to string and use such string as a hashing key. However, it's much more elegant, safe (what about ordering of keys within maps?), performant and memory-wise with Persistent structures. Also, until you restrict to well-behaving functions, there's no need to invalidate cache; you can cache anything, for as long as you want.

### Simplicity matters
Fast copying or equality done right are nice features, but this is not the only selling point here. Having different ways how to copy (shallow, deep) objects or how to compare them (== vs. equals in Java) introduces new complexity. Even if you get used to it, it still takes some part of your mental capabilities and can lead to errors.

### Structure sharing
PMap map1 = persist({'a': 'something', 'b': bigMap});
PMap map2 = a.assoc('a', 'something completely different');
Suppose you are interested, whether map1['b'] == map2['b']. Thanks to structure sharing, this is O(1) operation, which means it is amazingly fast - no need to traverse through the bigMap. Although it may sound unimportant at the first glance, it is what really enables fast caching of complex functions. Also, this is the reason, why [Om](https://github.com/swannodette/om/) framework is MUCH faster than Facebooks [React](http://facebook.github.io/react/).

## And what is the prize for this all
In the 2.0 release, we optimized memory consumption such that the only penalty for using Persistent
comes at lower speed. Although structure sharing makes the whole thing much more effective than naive
copy-it-all approach, Persistents are still slower than their mutable counterparts (note however, that on
the other hand, some operations runs significantly faster, so its hard to say something conclusive
here). Following numbers illustrate, how much slow are Persistent data structures when benchmarking either on DartVM
or Dart2JS on Node (the numbers are quite independent of the structure size):

* DartVM read speed: 2
* DartVM write speed: 12 (5 by using Transients)
* Dart2JS read speed: 3
* Dart2JS write speed: 14 (6 by using Transients)

Although the factors are quite big, the whole operation is still very fast and it probably won't be THE bottleneck which would slow down your app.

See [ImplementationDetails](https://github.com/polux/persistent/wiki/ImplementationDetails) and the [generated API documentation](http://polux.github.io/persistent/continuous/persistent/PersistentMap.html) for more information.
4 changes: 4 additions & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.js
*.js.map
*.js.deps
temp.out
22 changes: 0 additions & 22 deletions benchmark/map_bench.dart

This file was deleted.

23 changes: 0 additions & 23 deletions benchmark/map_bench_wordcount.csv

This file was deleted.

42 changes: 0 additions & 42 deletions benchmark/map_bench_wordcount.dart

This file was deleted.

62 changes: 62 additions & 0 deletions benchmark/map_memory/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
template_size = 1000

define RUNNER
function dartMainRunner(main, args){
main(process.argv.slice(2));
}
endef

export RUNNER

define INTRO
- - - - - - - -
Using (flat) map of size ${template_size}. Benchmark internally counts number of objects that fit
into 1GB heap space. Output is in bytes per one key->value storage place. Instances of keys and
values are shared between multiple copies of the structure we create, therefore their size do not
affect the result (much).
- - - - - - - -
endef

export INTRO


all: clean run


build/map_memory.js: map_memory.dart
mkdir -p build
dart2js -o build/tmp.js map_memory.dart
cat ../preamble/d8.js >> build/map_memory.js
cat build/tmp.js >> build/map_memory.js
echo "$$RUNNER" >> build/map_memory.js

clean:
rm -rf build


run: build/map_memory.js

@echo "$$INTRO"

# @echo -n "DartVM persistent: "
# @dart --old_gen_heap_size=1024 map_memory.dart ${template_size} persistent > build/temp.out 2>/dev/null
# @tail -1 build/temp.out
#
# @echo -n "DartVM map: "
# @dart --old_gen_heap_size=1024 map_memory.dart ${template_size} map > build/temp.out 2>/dev/null
# @tail -1 build/temp.out

@echo -n "NodeJS persistent: "
@ (! node --max-old-space-size=1024 build/map_memory.js ${template_size} persistent > build/temp.out) 2>/dev/null
@tail -1 build/temp.out

@echo -n "NodeJS map: "
@ (! node --max-old-space-size=1024 build/map_memory.js ${template_size} map > build/temp.out) 2>/dev/null
@tail -1 build/temp.out

@echo -n "NodeJS hashmap: "
@ (! node --max-old-space-size=1024 build/map_memory.js ${template_size} hashmap > build/temp.out) 2>/dev/null
@tail -1 build/temp.out

rm -f build/temp.out

54 changes: 54 additions & 0 deletions benchmark/map_memory/map_memory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2014, VacuumLabs.
// Copyright (c) 2012, Google Inc. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

// Authors are listed in the AUTHORS file

library map_memory;

import 'package:vacuum_persistent/persistent.dart';
import 'dart:collection';

Map template = {};

// here we will store the data to prevent it from garbage collection
List data = [];

var creators = {

"persistent": () => new PMap.fromMap(template),

"transient": (){
var res = new TMap();
template.forEach((k, v) => res.doAssoc(k, v));
return res;
},

"map": () => new Map.from(template),
"hashmap": () => new HashMap.from(template)
};

void run(int template_size, String mode) {

for (int i = 0; i < template_size; i++) {
template["$i".padLeft(8)] = "$i".padRight(8);
}

int allocated = 0;
for(bool go = true; go; allocated++){
try{
go = false;
var a = creators[mode]();
data.add(a);
go = true;
print(1073741824.0 / allocated / template_size);
} catch(e) {
data = null;
}
}
}

main(List<String> args){

run(int.parse(args[0]), args[1]);
}
Loading