phosphor-sectionlist
A data structure for a collection of variable sized sections.
A section list is well suited to managing row heights in virtually scrolling list controls. In these controls, most rows are uniform height while a handful of rows are variable sized. A pair of lists can be used to efficiently manage a virtually scrolling data grid.
A section list has guaranteed O(log n)
worst-case performance for
most operations, where n
is the number of variable sized sections.
Package Install
Prerequisites
npm install --save phosphor-sectionlist
Source Build
Prerequisites
git clone https://github.com/phosphorjs/phosphor-sectionlist.gitcd phosphor-sectionlistnpm install
Rebuild
npm run cleannpm run build
Run Tests
Follow the source build instructions first.
npm test
Build Docs
Follow the source build instructions first.
npm run docs
Navigate to docs/index.html
.
Supported Runtimes
The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.
- Node 0.12.7+
- IE 11+
- Firefox 32+
- Chrome 38+
Bundle for the Browser
Follow the package install instructions first.
npm install --save-dev browserifybrowserify myapp.js -o mybundle.js
Usage Examples
Note: This module is fully compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when using a language other than TypeScript.
; // Create a new list with 100 sections of size 10;list.insert0, 100, 10; // Prepend 20 sections of size 50list.insert0, 20, 50; // Append 10 sections of size 20list.insert120, 10, 20; // Insert 5 sections of size 5 in the middlelist.insert65, 5, 5; // Query the total count and sizelist.size; // 2225list.count; // 135 // Query for the index of various offsetslist.indexOf0; // 0list.indexOf2224; // 134list.indexOf155; // 3list.indexOf1035; // 23list.indexOf2003; // 122list.indexOf2038; // 125list.indexOf-100; // -1list.indexOf5000; // -1 // Query for the offset of various indiceslist.offsetOf0; // 0list.offsetOf134; // 2205list.offsetOf21; // 1010list.offsetOf68; // 1465list.offsetOf125; // 2025list.offsetOf-100; // -1list.offsetOf5000; // -1 // Query for the size of various indiceslist.sizeOf0; // 0list.sizeOf134; // 20list.sizeOf21; // 10list.sizeOf68; // 5list.sizeOf125; // 20list.sizeOf-100; // -1list.sizeOf5000; // -1 // Remove 10 sections starting at index 50list.remove50, 10;list.size; // 2125list.count; // 125 // Resize the first 20 sections to 1list.resize0, 20, 1;list.size; // 1145list.count; // 125list.sizeOf0; // 1list.sizeOf19; // 1list.sizeOf20; // 10