Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
86e46739
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
86e46739
编写于
6月 17, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove unused sortedList
上级
59fdb4a4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
367 deletion
+0
-367
src/vs/base/common/sortedList.ts
src/vs/base/common/sortedList.ts
+0
-256
src/vs/base/test/common/sortedList.test.ts
src/vs/base/test/common/sortedList.test.ts
+0
-111
未找到文件。
src/vs/base/common/sortedList.ts
已删除
100644 → 0
浏览文件 @
59fdb4a4
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
Arrays
=
require
(
'
vs/base/common/arrays
'
);
export
interface
IIterator
<
TValue
>
{
current
:
TValue
;
moveNext
():
boolean
;
hasNext
():
boolean
;
reset
():
void
;
dispose
():
void
;
}
export
interface
IIterable
<
TValue
>
{
getIterator
():
IIterator
<
TValue
>
;
}
export
interface
ISortedList
<
TKey
,
TValue
>
extends
IIterable
<
KeyValue
<
TKey
,
TValue
>>
{
/**
* Number of elements in a sorted list.
* O(1)
*/
count
:
number
;
/**
* Gets the value associated with the specified key.
* Returns null if there is no value associated with the key.
* O(log n)
*/
getValue
(
key
:
TKey
):
TValue
;
/**
* Gets an iterator over values.
* O(1)
*/
getValues
():
IIterator
<
TValue
>
;
/**
* Gets the value at the specified index.
* Returns null if index is out of bounds.
* O(1)
*/
getValueByIndex
(
index
:
number
):
TValue
;
/**
* Gets the key at the specified index.
* Returns null if index is out of bounds.
* O(1)
*/
getKey
(
index
:
number
):
TKey
;
/**
* Gets an iterator over keys.
* O(1)
*/
getKeys
():
IIterator
<
TKey
>
;
/**
* Returns the zero-based index of the specified key in a SortedList object.
* Returns -1 if the key is not found.
* O(log n)
*/
indexOfKey
(
key
:
TKey
):
number
;
/**
* Adds the specified key and value to the sorted list.
* O(n)
*/
add
(
key
:
TKey
,
value
:
TValue
):
void
;
/**
* Removes a value from the sorted list.
* Returns true if the value got removed, false otherwise.
* O(n)
*/
remove
(
key
:
TKey
):
boolean
;
}
export
interface
KeyValue
<
TKey
,
TValue
>
{
key
:
TKey
;
value
:
TValue
;
}
export
class
SortedList
<
TKey
,
TValue
>
implements
ISortedList
<
TKey
,
TValue
>
{
private
static
DEFAULT_COMPARATOR
=
function
<
TKey
>
(
first
:
TKey
,
second
:
TKey
)
{
return
first
<
second
?
-
1
:
first
>
second
?
1
:
0
;
};
private
keys
:
TKey
[];
private
values
:
TValue
[];
private
comparator
:
(
first
:
TKey
,
second
:
TKey
)
=>
number
;
constructor
(
comparator
?:
(
first
:
TKey
,
second
:
TKey
)
=>
number
)
{
this
.
keys
=
[];
this
.
values
=
[];
this
.
comparator
=
comparator
||
SortedList
.
DEFAULT_COMPARATOR
;
}
public
get
count
():
number
{
return
this
.
keys
.
length
;
}
public
getValueByIndex
(
index
:
number
):
TValue
{
if
(
0
<=
index
&&
index
<
this
.
values
.
length
)
{
return
this
.
values
[
index
];
}
return
null
;
}
public
getKey
(
index
:
number
):
TKey
{
if
(
0
<=
index
&&
index
<
this
.
keys
.
length
)
{
return
this
.
keys
[
index
];
}
return
null
;
}
public
getKeys
():
IIterator
<
TKey
>
{
return
new
ListIterator
<
TKey
>
(
this
.
keys
);
}
public
getValue
(
key
:
TKey
):
TValue
{
if
(
!
key
)
{
throw
new
Error
(
'
Key must be defined.
'
);
}
var
indexOfKey
=
this
.
indexOfKey
(
key
);
if
(
indexOfKey
>=
0
)
{
return
this
.
values
[
indexOfKey
];
}
return
null
;
}
public
getValues
():
IIterator
<
TValue
>
{
return
new
ListIterator
<
TValue
>
(
this
.
values
);
}
public
indexOfKey
(
key
:
TKey
):
number
{
if
(
!
key
)
{
throw
new
Error
(
'
Key must be defined.
'
);
}
return
Math
.
max
(
-
1
,
Arrays
.
binarySearch
(
this
.
keys
,
key
,
this
.
comparator
));
}
public
add
(
key
:
TKey
,
value
:
TValue
):
void
{
if
(
!
key
||
!
value
)
{
throw
new
Error
(
'
Key and value must be defined.
'
);
}
var
position
=
0
;
while
(
position
<
this
.
keys
.
length
&&
this
.
comparator
(
key
,
this
.
keys
[
position
])
>
0
)
{
position
++
;
}
this
.
keys
.
splice
(
position
,
0
,
key
);
this
.
values
.
splice
(
position
,
0
,
value
);
}
public
remove
(
key
:
TKey
):
boolean
{
if
(
!
key
)
{
throw
new
Error
(
'
Key must be defined.
'
);
}
var
indexOfKey
=
this
.
indexOfKey
(
key
);
if
(
indexOfKey
>=
0
)
{
this
.
values
.
splice
(
indexOfKey
,
1
);
this
.
keys
.
splice
(
indexOfKey
,
1
);
}
return
indexOfKey
>=
0
;
}
public
getIterator
():
IIterator
<
KeyValue
<
TKey
,
TValue
>>
{
return
new
SortedListIterator
<
TKey
,
TValue
>
(
this
.
keys
,
this
.
values
);
}
}
class
SortedListIterator
<
TKey
,
TValue
>
implements
IIterator
<
KeyValue
<
TKey
,
TValue
>>
{
private
keys
:
TKey
[];
private
values
:
TValue
[];
private
index
:
number
;
constructor
(
keys
:
TKey
[],
values
:
TValue
[])
{
this
.
keys
=
keys
;
this
.
values
=
values
;
this
.
index
=
-
1
;
}
public
get
current
():
KeyValue
<
TKey
,
TValue
>
{
if
(
this
.
index
<
0
||
this
.
keys
.
length
<
this
.
index
)
{
return
null
;
}
return
{
key
:
this
.
keys
[
this
.
index
],
value
:
this
.
values
[
this
.
index
]
};
}
public
moveNext
():
boolean
{
this
.
index
++
;
return
this
.
index
<
this
.
keys
.
length
;
}
public
hasNext
():
boolean
{
return
this
.
index
+
1
<
this
.
keys
.
length
;
}
public
reset
():
void
{
this
.
index
=
-
1
;
}
public
dispose
():
void
{
this
.
keys
=
null
;
this
.
values
=
null
;
}
}
class
ListIterator
<
TValue
>
implements
IIterator
<
TValue
>
{
private
values
:
TValue
[];
private
index
:
number
;
constructor
(
values
:
TValue
[])
{
this
.
values
=
values
;
this
.
index
=
-
1
;
}
public
get
current
():
TValue
{
if
(
this
.
index
<
0
||
this
.
values
.
length
<
this
.
index
)
{
return
null
;
}
return
this
.
values
[
this
.
index
];
}
public
moveNext
():
boolean
{
this
.
index
++
;
return
this
.
index
<
this
.
values
.
length
;
}
public
hasNext
():
boolean
{
return
this
.
index
+
1
<
this
.
values
.
length
;
}
public
reset
():
void
{
this
.
index
=
-
1
;
}
public
dispose
():
void
{
this
.
values
=
null
;
}
}
\ No newline at end of file
src/vs/base/test/common/sortedList.test.ts
已删除
100644 → 0
浏览文件 @
59fdb4a4
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
SortedList
=
require
(
'
vs/base/common/sortedList
'
);
function
getCuisineKeys
():
string
[]
{
return
[
'
german
'
,
'
swiss
'
,
'
french
'
,
'
italian
'
,
'
english
'
,
'
scotish
'
,
'
turksih
'
,
'
hungarian
'
,
'
serbian
'
,
'
swedish
'
,
'
russian
'
,
'
portugesse
'
,
'
american
'
,
'
japenesse
'
,
'
chinesse
'
,
'
bosnian
'
,
'
makedonian
'
,
'
libanese
'
,
'
mexican
'
,
'
thailand
'
];
}
function
getCuisineValues
():
string
[]
{
return
[
'
beer
'
,
'
cheese
'
,
'
wine
'
,
'
pizza
'
,
'
chips
'
,
'
whiskey
'
,
'
kebab
'
,
'
gulash
'
,
'
pljeska
'
,
'
salmon
'
,
'
vodka
'
,
'
shrimp
'
,
'
burger
'
,
'
susshi
'
,
'
sechuan
'
,
'
cevapcici
'
,
'
burek
'
,
'
falafel
'
,
'
burito
'
,
'
curryduck
'
];
}
function
shouldThrow
(
func
:
(
key
:
any
)
=>
any
,
key
:
any
):
void
{
try
{
func
(
key
);
assert
(
false
);
}
catch
(
e
)
{
assert
(
true
);
}
}
var
keys
=
getCuisineKeys
();
var
values
=
getCuisineValues
();
function
getCuisineList
(
withoutIterator
:
boolean
=
false
):
SortedList
.
ISortedList
<
string
,
string
>
{
var
result
=
new
SortedList
.
SortedList
<
string
,
string
>
(
withoutIterator
?
null
:
(
first
:
string
,
second
:
string
)
=>
{
return
first
.
localeCompare
(
second
);
});
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
result
.
add
(
keys
[
i
],
values
[
i
]);
}
return
result
;
}
suite
(
'
SortedList
'
,
()
=>
{
test
(
'
sorted list add
'
,
function
()
{
var
sortedList
=
getCuisineList
();
assert
.
equal
(
sortedList
.
count
,
keys
.
length
);
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
assert
.
equal
(
sortedList
.
getValue
(
keys
[
i
]),
values
[
i
]);
assert
(
sortedList
.
indexOfKey
(
keys
[
i
])
>=
0
);
assert
.
notEqual
(
sortedList
.
getValueByIndex
(
i
),
null
);
}
});
test
(
'
sorted list add with default comparator
'
,
function
()
{
var
sortedList
=
getCuisineList
(
true
/* without comparator */
);
assert
.
equal
(
sortedList
.
count
,
keys
.
length
);
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
assert
.
equal
(
sortedList
.
getValue
(
keys
[
i
]),
values
[
i
]);
assert
(
sortedList
.
indexOfKey
(
keys
[
i
])
>=
0
);
assert
.
notEqual
(
sortedList
.
getValueByIndex
(
i
),
null
);
}
});
test
(
'
sorted list remove
'
,
function
()
{
var
sortedList
=
getCuisineList
();
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
assert
(
sortedList
.
remove
(
keys
[
i
]));
}
assert
.
equal
(
sortedList
.
count
,
0
);
});
test
(
'
sorted list iterator
'
,
function
()
{
var
sortedList
=
getCuisineList
();
// <any> cast due to TS bug.
var
iterator
=
<
any
>
sortedList
.
getIterator
();
var
elementCount
=
0
;
while
(
iterator
.
moveNext
())
{
elementCount
++
;
assert
(
keys
.
indexOf
(
iterator
.
current
.
key
)
>=
0
);
assert
(
values
.
indexOf
(
iterator
.
current
.
value
)
>=
0
);
}
assert
.
equal
(
elementCount
,
sortedList
.
count
);
iterator
.
reset
();
elementCount
=
0
;
assert
(
iterator
.
hasNext
());
while
(
iterator
.
moveNext
())
{
elementCount
++
;
assert
(
keys
.
indexOf
(
iterator
.
current
.
key
)
>=
0
);
assert
(
values
.
indexOf
(
iterator
.
current
.
value
)
>=
0
);
}
assert
(
!
iterator
.
hasNext
());
assert
.
equal
(
elementCount
,
sortedList
.
count
);
});
test
(
'
sorted list bad op
'
,
function
()
{
var
sortedList
=
getCuisineList
();
assert
.
equal
(
sortedList
.
getKey
(
127
),
null
);
assert
.
equal
(
sortedList
.
getKey
(
-
1
),
null
);
assert
.
equal
(
sortedList
.
getValue
(
'
banana
'
),
null
);
assert
.
equal
(
sortedList
.
remove
(
'
unexistingKey
'
),
false
);
assert
.
equal
(
sortedList
.
getValueByIndex
(
-
4
),
null
);
assert
.
equal
(
sortedList
.
getValueByIndex
(
1114
),
null
);
assert
.
equal
(
sortedList
.
indexOfKey
(
'
fakeKey
'
),
-
1
);
shouldThrow
(
sortedList
.
indexOfKey
,
null
);
shouldThrow
(
sortedList
.
getValue
,
null
);
shouldThrow
(
sortedList
.
remove
,
null
);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录