lists 0.0.22

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 52

lists

Collection of the lists (BitList, FilledList, GroupedRangeList, ListPointer, RangeList, SparseBoolList, SparseList, StepList, WrappedList).

Version: 0.0.21

import "package:lists/lists.dart";

void main() {
  bitList();
  filledList();
  rangeList();
  sparseBoolList();
  sparseList();
  stepList();
  wrappedList();
}

void bitList() {
  // The bit state list with 65536 elements
  // Real size of the list (in memory) 30 times less
  // Exact size 2185 elements of 'Smi' values
  var list = new BitList(65536);
  list.set(32767);
  print(list.get(32767));

  // The list with 65536 elements set to true
  list = new BitList(65536, true);
  print(list.get(32767));

  // The list with 1073741824 elements
  list = new BitList(1073741824);
}

void filledList() {
  // The read only list with 40 values of "="
  var list = new FilledList<String>(40, "=");
  print("${list.join()}");

  // The list with 10000000000000 values of "hello"
  list = new FilledList<String>(10000000000000, "hello");
}

void rangeList() {
  // The values from 0 to 10
  var list = new RangeList(0, 10);
  print("${list.join(", ")}");

  // The same values in reversed order
  var reversed = list.reversed;
  print("${reversed.join(", ")}");

  // The same list with step 2
  var list2 = list.toStepList(2);
  print("${list2.join(", ")}");

  //  The values from -10000000000000 to 10000000000000
  list = new RangeList(10000000000000, 10000000000000);
}

void sparseBoolList() {
  // Really big size
  var length = 2 * 1024 * 1024 * 1024;
  var list = new SparseBoolList(length: length);
  var groupCount = 0;
  var offset = 0;
  print("SparseBoolList: ${_format(length)} length.");
  var sw = new Stopwatch();
  sw.start();
  while (true) {
    var size = 128 * 1024;
    //list.addGroup(_grp(offset, offset + size, true));
    list.addGroup(new GroupedRangeList(offset, offset + size, true));
    offset += size + 128 * 1024;
    groupCount++;
    if (offset >= length) {
      break;
    }
  }
  //
  sw.stop();
  var elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseBoolList: ${_format(groupCount)} groups added in $elapsed sec.");
  //
  var acessed = 0;
  var elementCount = length / 10;
  //
  sw.reset();
  sw.start();
  for (var i = 0; i < length; i += 100) {
    var x = list[i];
    acessed++;
  }

  sw.stop();
  elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseBoolList: ${_format(acessed)} elements accessed in $elapsed sec."
      );
}

void sparseList() {
  // Count is 50000 elements
  var count = 50000;
  var list = new SparseList();
  var offset = 0;
  var sw = new Stopwatch();
  sw.start();
  for (var i = 0; i < count; i++) {
    offset += 100;
    var size = 100;
    //list.addGroup(_grp(offset, offset + size, i));
    list.addGroup(new GroupedRangeList(offset, offset + size, i));
    offset += size;
  }

  sw.stop();
  var elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseList: ${_format(count)} groups added in $elapsed sec.");
  // Access all elements
  sw.reset();
  sw.start();
  var length = list.length;
  for (var i = 0; i < length; i++) {
    var x = list[i];
  }

  sw.stop();
  elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseList: ${_format(length)} elements accessed in $elapsed sec.");
}

void stepList() {
  // The values from 0 to 10
  var list = new StepList(0, 10);
  print("${list.join(", ")}");

  // The values from 10 to 0
  list = new StepList(10, 0);
  print("${list.join(", ")}");

  // The values from 0 to 10 with step 2
  list = new StepList(0, 10, 2);
  print("${list.join(", ")}");

  // The values from 10 to 0 with step -2
  list = new StepList(10, 0, -2);
  print("${list.join(", ")}");

  // The values from 0 to 255 with step 64
  const MIN_BYTE = 0;
  const MAX_BYTE = 255;
  list = new StepList(MIN_BYTE, MAX_BYTE, (MAX_BYTE >> 2) + 1);
  print("${list.join(", ")}");

  // The values from -10000000000000 to 10000000000000 with step 1
  list = new StepList(-10000000000000, 10000000000000);
}

void wrappedList() {
  // The read only wrapper for list
  var source = [0, 1, 2, 3];
  var list = new WrappedList<int>(source);
  try {
    list[0] = 0;
  } catch (e, s) {
    print("$e");
  }

  try {
    list.length = 0;
  } catch (e, s) {
    print("$e");
  }
}

GroupedRangeList _grp(int start, int end, dynamic key) {
  return new GroupedRangeList(start, end, key);
}

String _format(int number) {
  var string = number.toString();
  var length = string.length;
  var list = <String>[];
  var count = 0;
  for (var i = length - 1; i >= 0; i--) {
    list.add(string[i]);
    if (count++ == 2) {
      list.add(" ");
      count = 0;
    }
  }

  return list.reversed.join();
}

0.0.22

  • Added strong_mode option

0.0.21

  • Added ListPointer which can be used effectively when porting the programs written in the C language

0.0.20

  • Added method getAllSpace(RangeList range) => List<GroupedRangeList<E>> to SparseList<E>

0.0.19

  • Added method getAlignedGroups(RangeList range) => List<GroupedRangeList<E>> to SparseList<E>

0.0.18

  • Fixed bug in SparseList.getGroups()

0.0.17

  • Added field frozen => bool to SparseList<E>
  • Added method freeze() => void to SparseList<E>
  • SparseList<E> now can be frozen

0.0.16

  • Fixed bug (change length of fixed list) in SparseList.addGroup()

0.0.15

  • Fixed bug (change length of fixed list) in SparseList.removeValues()
  • Fixed bug (change length of fixed list) in SparseList.trim()

0.0.14

  • Added method trim() => void to SparseList<E>
  • Fixed bug (decrease length) in SparseList.removeValues()
  • Improved performance of modifications SparseList<E>

0.0.12

  • Fixed bug (decrease length) in SparseList.removeValues()

0.0.11

  • Fixed bug in SparseList.removeValues()

0.0.10

  • Improved performance of modifications SparseList<E>
  • Removed limitations on the bounds of the range in SparseList.removeValues()

0.0.9

  • Added method getIndexes() => Iterable<int> to SparseList<E>

0.0.8

  • Added field groups => List<GroupedRangeList<E>> to SparseList<E>

0.0.7

  • Added field end => int to SparseList<E>
  • Added field start => int to SparseList<E>

0.0.6

  • Added class SparseBoolList
  • Modified method in SparseList<E> from getGroups(RangeList range) to getGroups([RangeList range])

0.0.5

  • Improved (up to 15%) the performance of the SparseList.addGroup() when the group added to the end

0.0.4

  • Added class GroupedRangeList<E>
  • Added class SparseList<E>
  • Added method includes(RangeList other) => bool to RangeList
  • Added method intersection(RangeList other) => RangeList to RangeList
  • Added method subtract(RangeList other) => List<RangeList> to RangeList
  • Added operator +(RangeList other) => RangeList to RangeList

example/example.dart

import "package:lists/lists.dart";

void main() {
  bitList();
  filledList();
  rangeList();
  sparseBoolList();
  sparseList();
  stepList();
  wrappedList();
}

void bitList() {
  // The bit state list with 65536 elements
  // Real size of the list (in memory) 30 times less
  // Exact size 2185 elements of 'Smi' values
  var list = new BitList(65536);
  list.set(32767);
  print(list.get(32767));

  // The list with 65536 elements set to true
  list = new BitList(65536, true);
  print(list.get(32767));

  // The list with 1073741824 elements
  list = new BitList(1073741824);
}

void filledList() {
  // The read only list with 40 values of "="
  var list = new FilledList<String>(40, "=");
  print("${list.join()}");

  // The list with 10000000000000 values of "hello"
  list = new FilledList<String>(10000000000000, "hello");
}

void rangeList() {
  // The values from 0 to 10
  var list = new RangeList(0, 10);
  print("${list.join(", ")}");

  // The same values in reversed order
  var reversed = list.reversed;
  print("${reversed.join(", ")}");

  // The same list with step 2
  var list2 = list.toStepList(2);
  print("${list2.join(", ")}");

  //  The values from -10000000000000 to 10000000000000
  list = new RangeList(10000000000000, 10000000000000);
}

void sparseBoolList() {
  // Really big size
  var length = 2 * 1024 * 1024 * 1024;
  var list = new SparseBoolList(length: length);
  var groupCount = 0;
  var offset = 0;
  print("SparseBoolList: ${_format(length)} length.");
  var sw = new Stopwatch();
  sw.start();
  while (true) {
    var size = 128 * 1024;
    //list.addGroup(_grp(offset, offset + size, true));
    list.addGroup(new GroupedRangeList(offset, offset + size, true));
    offset += size + 128 * 1024;
    groupCount++;
    if (offset >= length) {
      break;
    }
  }
  //
  sw.stop();
  var elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseBoolList: ${_format(groupCount)} groups added in $elapsed sec.");
  //
  var acessed = 0;
  var elementCount = length / 10;
  //
  sw.reset();
  sw.start();
  for (var i = 0; i < length; i += 100) {
    var x = list[i];
    acessed++;
  }

  sw.stop();
  elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseBoolList: ${_format(acessed)} elements accessed in $elapsed sec."
      );
}

void sparseList() {
  // Count is 50000 elements
  var count = 50000;
  var list = new SparseList();
  var offset = 0;
  var sw = new Stopwatch();
  sw.start();
  for (var i = 0; i < count; i++) {
    offset += 100;
    var size = 100;
    //list.addGroup(_grp(offset, offset + size, i));
    list.addGroup(new GroupedRangeList(offset, offset + size, i));
    offset += size;
  }

  sw.stop();
  var elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseList: ${_format(count)} groups added in $elapsed sec.");
  // Access all elements
  sw.reset();
  sw.start();
  var length = list.length;
  for (var i = 0; i < length; i++) {
    var x = list[i];
  }

  sw.stop();
  elapsed = (sw.elapsedMilliseconds / 1000);
  print("SparseList: ${_format(length)} elements accessed in $elapsed sec.");
}

void stepList() {
  // The values from 0 to 10
  var list = new StepList(0, 10);
  print("${list.join(", ")}");

  // The values from 10 to 0
  list = new StepList(10, 0);
  print("${list.join(", ")}");

  // The values from 0 to 10 with step 2
  list = new StepList(0, 10, 2);
  print("${list.join(", ")}");

  // The values from 10 to 0 with step -2
  list = new StepList(10, 0, -2);
  print("${list.join(", ")}");

  // The values from 0 to 255 with step 64
  const MIN_BYTE = 0;
  const MAX_BYTE = 255;
  list = new StepList(MIN_BYTE, MAX_BYTE, (MAX_BYTE >> 2) + 1);
  print("${list.join(", ")}");

  // The values from -10000000000000 to 10000000000000 with step 1
  list = new StepList(-10000000000000, 10000000000000);
}

void wrappedList() {
  // The read only wrapper for list
  var source = [0, 1, 2, 3];
  var list = new WrappedList<int>(source);
  try {
    list[0] = 0;
  } catch (e, s) {
    print("$e");
  }

  try {
    list.length = 0;
  } catch (e, s) {
    print("$e");
  }
}

GroupedRangeList _grp(int start, int end, dynamic key) {
  return new GroupedRangeList(start, end, key);
}

String _format(int number) {
  var string = number.toString();
  var length = string.length;
  var list = <String>[];
  var count = 0;
  for (var i = length - 1; i >= 0; i--) {
    list.add(string[i]);
    if (count++ == 2) {
      list.add(" ");
      count = 0;
    }
  }

  return list.reversed.join();
}

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  lists: "^0.0.22"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:lists/lists.dart';
        
Version Uploaded Documentation Archive
0.0.22 Jun 6, 2017 Go to the documentation of lists 0.0.22 Download lists 0.0.22 archive
0.0.21 Feb 23, 2015 Go to the documentation of lists 0.0.21 Download lists 0.0.21 archive
0.0.20 Oct 4, 2014 Go to the documentation of lists 0.0.20 Download lists 0.0.20 archive
0.0.19 Sep 12, 2014 Go to the documentation of lists 0.0.19 Download lists 0.0.19 archive
0.0.18 Aug 28, 2014 Go to the documentation of lists 0.0.18 Download lists 0.0.18 archive
0.0.17 Aug 24, 2014 Go to the documentation of lists 0.0.17 Download lists 0.0.17 archive
0.0.16 Aug 20, 2014 Go to the documentation of lists 0.0.16 Download lists 0.0.16 archive
0.0.15 Aug 20, 2014 Go to the documentation of lists 0.0.15 Download lists 0.0.15 archive
0.0.14 Aug 20, 2014 Go to the documentation of lists 0.0.14 Download lists 0.0.14 archive
0.0.12 Aug 19, 2014 Go to the documentation of lists 0.0.12 Download lists 0.0.12 archive

All 21 versions...

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
9 / 100
Health:
Code health derived from static analysis. [more]
97 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95 / 100
Overall score:
Weighted score of the above. [more]
52

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:lists/lists.dart.

Suggestions

  • Fix lib/src/list_pointer.dart.

    Strong-mode analysis of lib/src/list_pointer.dart failed with the following error:

    line: 161 col: 3
    Invalid override. The type of 'ListPointer.[]=' ('(int, T) → void') isn't a subtype of 'List<dynamic>.[]=' ('(int, dynamic) → void').

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Dev dependencies
build_tools any
test any