0.2.4 • Published 10 months ago

@x-oasis/prefix-interval-tree v0.2.4

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

@x-oasis/prefix-interval-tree

Installation

$ npm i @x-oasis/prefix-interval-tree

How to use

import PrefixIntervalTree from '@x-oasis/prefix-interval-tree'

How to run test

$ pnpm test

API

PrefixIntervalTree Constructor

const intervalTree = new PrefixIntervalTree([2,5,7])

const intervalTree = new PrefixIntervalTree(10)

Total interval tree array length is power of 2, such as 8, 16, 32; and the input length value means the half size, which means 10 will result in 2^4 = 16 first, then patch on interval tree, it will be total 2 * 16 = 32.

getHeap

getHeap(): number[]

getActualSize

Basically, interval tree's size is this._half, they all have default 0 value. when you want to get the actual size which has been set with value, then call this method.

get(index: number)

get(index: number): number

get the index value

set(index: number)

set (index: number): boolean

To update the index value in interval tree, its parent will be updated as accordingly.

computeRange(minValue: number, maxValue: number)

computeRange(minValue: number, maxValue: number): {
  startIndex: number
  endIndex: number
}
  • startIndex: the biggest index less than or equal minValue;
  • endIndex: the smallest index greater than maxValue;

when using the return value, endIndex item should not be included.

const arr = []
const intervalTree = new PrefixIntervalTree(arr)

const { startIndex, endIndex } = intervalTree.computeRange(100, 200);

const itemsInViewport = arr.slice(startIndex, endIndex)
0.2.1

10 months ago

0.2.0

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.4

10 months ago

0.1.35

12 months ago

0.1.30

2 years ago

0.1.31

2 years ago

0.1.32

2 years ago

0.1.33

2 years ago

0.1.34

2 years ago

0.1.15

2 years ago

0.1.27

2 years ago

0.1.28

2 years ago

0.1.29

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.26

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago