1 | export class SkipListNode<T>{
|
2 | private next: Array<SkipListNode<T>>;
|
3 | private prev: Array<SkipListNode<T>>;
|
4 | constructor(private readonly item: T= null){
|
5 | this.next = [];
|
6 | this.prev = [];
|
7 | }
|
8 |
|
9 | public getItem(){
|
10 | return this.item;
|
11 | }
|
12 |
|
13 | public getNext(level: number){
|
14 | return this.next[level];
|
15 | }
|
16 |
|
17 | public setNext(level: number, node: SkipListNode<T>){
|
18 | this.next[level] = node;
|
19 | }
|
20 |
|
21 | public getPrev(level: number){
|
22 | return this.prev[level];
|
23 | }
|
24 |
|
25 | public setPrev(level: number, node: SkipListNode<T>){
|
26 | this.prev[level] = node;
|
27 | }
|
28 |
|
29 | public deleteLastLevel(){
|
30 | this.next.length--;
|
31 | }
|
32 |
|
33 | public getNextLevel(){
|
34 | return this.next.length;
|
35 | }
|
36 |
|
37 | public getPrevLevel(){
|
38 | return this.prev.length;
|
39 | }
|
40 |
|
41 | public getHeight(){
|
42 | return Math.max(this.getPrevLevel(), this.getNextLevel());
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | }
|