simple_sparse_list 0.1.3 copy "simple_sparse_list: ^0.1.3" to clipboard
simple_sparse_list: ^0.1.3 copied to clipboard

A simple and efficient implementation of an unmodifiable sparse list based on the binary search algorithm.

example/example.dart

import 'package:simple_sparse_list/ranges_helper.dart';
import 'package:simple_sparse_list/simple_sparse_list.dart';

void main(List<String> args) {
  _test(32);
  _test(48);
  _test(73);
  _test(100);
  _test(320);
  _test(0x10ffff);

  const values = [
    (0, 0, {'A'}),
    (0, 2, {'B'}),
    (3, 4, {'B'}),
    (5, 6, {'C'}),
    (8, 9, {'D'}),
    (9, 10, {'E'}),
  ];

  final combined = combineRanges<Set<String>>(values, combine: (x, y) {
    return {...x, ...y};
  }, compare: (x, y) {
    if (x.length != y.length) {
      return false;
    }

    for (final element in y) {
      if (!x.contains(element)) {
        return false;
      }
    }

    return true;
  });

  print(values);
  print(combined);
}

final _data = [
  (48, 57, Letter.number),
  (65, 90, Letter.upperCase),
  (97, 122, Letter.lowerCase),
];

final _list = SparseList(_data, Letter.unknown, length: 0x10ffff + 1);

void _test(int c) {
  final kind = _list[c];
  print('$c: $kind');
}

enum Letter { lowerCase, number, unknown, upperCase }
0
likes
160
points
42.1k
downloads

Publisher

unverified uploader

Weekly Downloads

A simple and efficient implementation of an unmodifiable sparse list based on the binary search algorithm.

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on simple_sparse_list