UNPKG

1.36 kBPlain TextView Raw
1export 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 // public SetHeight(height:number)
46 // {
47 // const newNext = new SkipListNode[height];
48 // const newPrev = new SkipListNode[height];
49 // const count = Math.min(this.next.length, height);
50 // for (let i = 0; i < count; i++)
51 // {
52 // newNext[i] = this.next[i];
53 // newPrev[i] = this.prev[i];
54 // }
55 // this.next = newNext;
56 // this.prev = newPrev;
57 // }
58}