nv-facutil-fixed-cache-cursor
v1.0.2
Published
nv-facutil-fixed-cache-cursor ============================= - mini cache with cursor - same as https://www.npmjs.com/package/nv-facutil-cache-cursor - for size < 8 using, for performance - fst,ppprev, pprev, prev, current, next,nnext,nnnext,lst - forward
Downloads
3
Readme
nv-facutil-fixed-cache-cursor
- mini cache with cursor, its just a array-of-size-8
- same as https://www.npmjs.com/package/nv-facutil-cache-cursor
- for size < 8 using, for performance
- fst,ppprev, pprev, prev, current, next,nnext,nnnext,lst
- forward ,backword, push,pop, push_and_forward ,pop_and_backward
install
- npm install nv-facutil-fixed-cache-cursor
usage
const Cache = require("nv-facutil-fixed-cache-cursor");
example
var cache = new Cache()
/*
> cache
Cache(8) [
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined, undefined
]
*/
cache.push_and_forward(10)
/*
10
> cache.curr_
10
> cache.cursor_
0
> cache.length_
1
> cache
Cache(8) [
10, undefined,
undefined, undefined,
undefined, undefined,
undefined, undefined
]
>
*/
cache.push(20)
/*
> cache
Cache(8) [
10, 20,
undefined, undefined,
undefined, undefined,
undefined, undefined
]
>
> cache.curr_
10
> cache.cursor_
0
> cache.length_
2
>
*/
cache.push(30)
cache.push(40)
/*
> cache.cursor_
0
> cache.curr_
10
> cache.length_
4
> cache
Cache(8) [
10, 20,
30, 40,
undefined, undefined,
undefined, undefined
]
*/
cache.forward()
/*
20
> cache.curr_
20
*/
cache.forward(2)
/*
40
> cache.curr_
40
>
*/
cache.forward()
cache.forward()
cache.forward()
/*
> cache.curr_
40
>
*/
cache.backward()
/*
>
30
*/
cache.backward()
/*
20
>
> cache.curr_
20
>
*/
cache.push(50)
cache.push(60)
cache.push(70)
cache.push(80)
/*
> cache
Cache(8) [
10, 20, 30, 40,
50, 60, 70, 80
]
>
> cache.curr_
20
>
*/
cache.push(100)
/*
> cache
Cache(8) [
20, 30, 40, 50,
60, 70, 80, 100
]
> cache.curr_
30
>
*/
cache.forward(6)
/*
100
>
*/
cache.forward()
cache.forward()
cache.forward()
/*
100
>
*/
cache.pop_and_backward()
// different behavior from normal pop, it returned current not the popped,
/*
> cache.pop_and_backward()
80
> cache
Cache(8) [ 20, 30, 40, 50, 60, 70, 80, undefined ]
> cache.curr_
80
>
*/
cache.pop_and_backward()
cache.pop_and_backward()
cache.pop_and_backward()
cache.pop_and_backward()
/*
> cache.pop_and_backward()
70
> cache.pop_and_backward()
60
> cache.pop_and_backward()
50
> cache.pop_and_backward()
40
> cache
Cache(8) [
20, 30,
40, undefined,
undefined, undefined,
undefined, undefined
]
> cache.curr_
40
> cache.length_
3
>
*/
cache.pop_and_backward()
cache.pop_and_backward()
cache.pop_and_backward()
/*
null
> cache
Cache(8) [
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined, undefined
]
>
> cache.pop_and_backward()
already empty
null
> cache.curr_
null
> cache.length_
0
>
*/
cache.push_and_forward(11)
cache.push_and_forward(12)
cache.push_and_forward(13)
cache.push(14)
cache.push(15)
cache.push(16)
/*
> cache
Cache(8) [ 11, 12, 13, 14, 15, 16, undefined, undefined ]
> cache.curr_
13
>
*/
cache.forward()
/*
> cache.forward()
14
> cache
Cache(8) [ 11, 12, 13, 14, 15, 16, undefined, undefined ]
>
*/
cache.push(17)
/*
> cache
Cache(8) [ 11, 12, 13, 14, 15, 16, 17, undefined ]
> cache.curr_
14
>
*/
getter : for token-cache using, most language lookahead(3) lookback(3) is enough
cache.ppprev_
cache.pprev_
cache.prev_
cache.curr_
cache.next_
cache.nnext_
cache.nnnext_
/*
> cache.ppprev_
11
> cache.pprev_
12
> cache.prev_
13
> cache.curr_
14
> cache.next_
15
> cache.nnext_
16
> cache.nnnext_
17
>
*/
slice
cache.slice_lt_cursor_
cache.slice_le_cursor_
cache.slice_ge_cursor_
cache.slice_gt_cursor_
/*
> cache.slice_lt_cursor_
[ 11, 12, 13 ]
>
> cache.slice_le_cursor_
[ 11, 12, 13, 14 ]
>
> cache.slice_ge_cursor_
[ 14, 15, 16, 17]
>
> cache.slice_gt_cursor_
[ 15, 16, 17]
>
*/
clear
cache.clear()
/*
> cache
Cache(8) [
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined, undefined
]
>
*/
forbidden, for safe
> cache.shift()
Uncaught 'unreachable'
> cache.splice()
Uncaught 'unreachable'
>
> cache.unshift()
Uncaught 'unreachable'
>
METHODS
cache.b cache.backward cache.can_backward_max_steps_
cache.can_forward_max_steps_ cache.clear cache.constructor
cache.curr_ cache.cursor_ cache.f
cache.forward cache.fst_ cache.is_cant_backward_one
cache.is_cant_forward_one cache.is_cursor_at_max cache.is_cursor_at_min
cache.is_empty cache.length_ cache.lst_
cache.max_cursor_ cache.min_cursor_ cache.next_
cache.nnext_ cache.nnnext_ cache.pop
cache.pop_and_backward cache.pop_one cache.ppprev_
cache.pprev_ cache.prev_ cache.push
cache.push_and_forward cache.push_index_ cache.safe_pop
cache.shift cache.slice_ge_cursor_ cache.slice_gt_cursor_
cache.slice_le_cursor_ cache.slice_lt_cursor_ cache.splice
cache.unshift
APIS
- Cache._push
- Cache._copy
LICENSE
- ISC