persistent 1.0.0 copy "persistent: ^1.0.0" to clipboard
persistent: ^1.0.0 copied to clipboard

Dart 1 only

Efficient persistent data structures for Dart. "Persistent" means immutable here, not "saved on disk".

Efficient Persistent Data Structures #

Mostly efficient persistent maps and sets for now. Also option types.

"Persistent" means immutable here, not "saved on disk".

import 'package:persistent/persistent.dart';

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});

  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()

  final m3 = m1.delete('a');
  print(m1);  // {a: 1, b: 2}
  print(m3);  // {b: 2}

  final m4 = m1.union(m2, (n,m) => n + m);
  print(m4);  // {c: 4, a: 4, b: 2}

  final m5 = m1.mapValues((n) => n + 1);
  print(m5);  // {a: 2, b: 3}

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

Try it! #

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

More #

See ImplementationDetails and the generated API documentation for more information.

0
likes
35
pub points
0%
popularity

Publisher

unverified uploader

Efficient persistent data structures for Dart. "Persistent" means immutable here, not "saved on disk".

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

More

Packages that depend on persistent