Skip to content

Commit 2edbe68

Browse files
authored
Merge pull request microsoft#106225 from LeuisKen/master
Fix microsoft#106213
2 parents 1c3d3ae + b985f22 commit 2edbe68

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/vs/base/common/skipList.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class SkipList<K, V> implements Map<K, V> {
2222
readonly [Symbol.toStringTag] = 'SkipList';
2323

2424
private _maxLevel: number;
25-
private _level: number = 1;
25+
private _level: number = 0;
2626
private _header: Node<K, V>;
2727
private _size: number = 0;
2828

@@ -122,7 +122,7 @@ export class SkipList<K, V> implements Map<K, V> {
122122

123123
private static _search<K, V>(list: SkipList<K, V>, searchKey: K, comparator: Comparator<K>) {
124124
let x = list._header;
125-
for (let i = list._level; i >= 0; i--) {
125+
for (let i = list._level - 1; i >= 0; i--) {
126126
while (x.forward[i] && comparator(x.forward[i].key, searchKey) < 0) {
127127
x = x.forward[i];
128128
}
@@ -137,7 +137,7 @@ export class SkipList<K, V> implements Map<K, V> {
137137
private static _insert<K, V>(list: SkipList<K, V>, searchKey: K, value: V, comparator: Comparator<K>) {
138138
let update: Node<K, V>[] = [];
139139
let x = list._header;
140-
for (let i = list._level; i >= 0; i--) {
140+
for (let i = list._level - 1; i >= 0; i--) {
141141
while (x.forward[i] && comparator(x.forward[i].key, searchKey) < 0) {
142142
x = x.forward[i];
143143
}
@@ -152,13 +152,13 @@ export class SkipList<K, V> implements Map<K, V> {
152152
// insert
153153
let lvl = SkipList._randomLevel(list);
154154
if (lvl > list._level) {
155-
for (let i = list._level + 1; i <= lvl; i++) {
155+
for (let i = list._level; i < lvl; i++) {
156156
update[i] = list._header;
157157
}
158158
list._level = lvl;
159159
}
160160
x = new Node<K, V>(lvl, searchKey, value);
161-
for (let i = 0; i <= lvl; i++) {
161+
for (let i = 0; i < lvl; i++) {
162162
x.forward[i] = update[i].forward[i];
163163
update[i].forward[i] = x;
164164
}
@@ -177,7 +177,7 @@ export class SkipList<K, V> implements Map<K, V> {
177177
private static _delete<K, V>(list: SkipList<K, V>, searchKey: K, comparator: Comparator<K>) {
178178
let update: Node<K, V>[] = [];
179179
let x = list._header;
180-
for (let i = list._level; i >= 0; i--) {
180+
for (let i = list._level - 1; i >= 0; i--) {
181181
while (x.forward[i] && comparator(x.forward[i].key, searchKey) < 0) {
182182
x = x.forward[i];
183183
}
@@ -194,7 +194,7 @@ export class SkipList<K, V> implements Map<K, V> {
194194
}
195195
update[i].forward[i] = x.forward[i];
196196
}
197-
while (list._level >= 1 && list._header.forward[list._level] === NIL) {
197+
while (list._level > 0 && list._header.forward[list._level - 1] === NIL) {
198198
list._level -= 1;
199199
}
200200
return true;

0 commit comments

Comments
 (0)