Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1edc8c6f
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,发现更多精彩内容 >>
提交
1edc8c6f
编写于
1月 03, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use ReadonlyArray in more places
上级
a179a4f1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
16 deletion
+16
-16
src/vs/base/common/arrays.ts
src/vs/base/common/arrays.ts
+16
-16
未找到文件。
src/vs/base/common/arrays.ts
浏览文件 @
1edc8c6f
...
...
@@ -46,7 +46,7 @@ export function equals<T>(one: ReadonlyArray<T> | undefined, other: ReadonlyArra
return
true
;
}
export
function
binarySearch
<
T
>
(
array
:
T
[]
,
key
:
T
,
comparator
:
(
op1
:
T
,
op2
:
T
)
=>
number
):
number
{
export
function
binarySearch
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
key
:
T
,
comparator
:
(
op1
:
T
,
op2
:
T
)
=>
number
):
number
{
let
low
=
0
,
high
=
array
.
length
-
1
;
...
...
@@ -69,7 +69,7 @@ export function binarySearch<T>(array: T[], key: T, comparator: (op1: T, op2: T)
* are located before all elements where p(x) is true.
* @returns the least x for which p(x) is true or array.length if no element fullfills the given function.
*/
export
function
findFirstInSorted
<
T
>
(
array
:
T
[]
,
p
:
(
x
:
T
)
=>
boolean
):
number
{
export
function
findFirstInSorted
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
p
:
(
x
:
T
)
=>
boolean
):
number
{
let
low
=
0
,
high
=
array
.
length
;
if
(
high
===
0
)
{
return
0
;
// no children
...
...
@@ -135,7 +135,7 @@ function _sort<T>(a: T[], compare: Compare<T>, lo: number, hi: number, aux: T[])
}
export
function
groupBy
<
T
>
(
data
:
T
[]
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
):
T
[][]
{
export
function
groupBy
<
T
>
(
data
:
ReadonlyArray
<
T
>
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
):
T
[][]
{
const
result
:
T
[][]
=
[];
let
currentGroup
:
T
[]
|
undefined
=
undefined
;
for
(
const
element
of
mergeSort
(
data
.
slice
(
0
),
compare
))
{
...
...
@@ -156,7 +156,7 @@ interface IMutableSplice<T> extends ISplice<T> {
/**
* Diffs two *sorted* arrays and computes the splices which apply the diff.
*/
export
function
sortedDiff
<
T
>
(
before
:
T
[],
after
:
T
[]
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
):
ISplice
<
T
>
[]
{
export
function
sortedDiff
<
T
>
(
before
:
ReadonlyArray
<
T
>
,
after
:
ReadonlyArray
<
T
>
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
):
ISplice
<
T
>
[]
{
const
result
:
IMutableSplice
<
T
>
[]
=
[];
function
pushSplice
(
start
:
number
,
deleteCount
:
number
,
toInsert
:
T
[]):
void
{
...
...
@@ -215,7 +215,7 @@ export function sortedDiff<T>(before: T[], after: T[], compare: (a: T, b: T) =>
* @param after
* @param compare
*/
export
function
delta
<
T
>
(
before
:
T
[],
after
:
T
[]
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
):
{
removed
:
T
[],
added
:
T
[]
}
{
export
function
delta
<
T
>
(
before
:
ReadonlyArray
<
T
>
,
after
:
ReadonlyArray
<
T
>
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
):
{
removed
:
T
[],
added
:
T
[]
}
{
const
splices
=
sortedDiff
(
before
,
after
,
compare
);
const
removed
:
T
[]
=
[];
const
added
:
T
[]
=
[];
...
...
@@ -238,7 +238,7 @@ export function delta<T>(before: T[], after: T[], compare: (a: T, b: T) => numbe
* @param n The number of elements to return.
* @return The first n elemnts from array when sorted with compare.
*/
export
function
top
<
T
>
(
array
:
T
[]
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
,
n
:
number
):
T
[]
{
export
function
top
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
,
n
:
number
):
T
[]
{
if
(
n
===
0
)
{
return
[];
}
...
...
@@ -284,7 +284,7 @@ export function topAsync<T>(array: T[], compare: (a: T, b: T) => number, n: numb
});
}
function
topStep
<
T
>
(
array
:
T
[]
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
,
result
:
T
[],
i
:
number
,
m
:
number
):
void
{
function
topStep
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
compare
:
(
a
:
T
,
b
:
T
)
=>
number
,
result
:
T
[],
i
:
number
,
m
:
number
):
void
{
for
(
const
n
=
result
.
length
;
i
<
m
;
i
++
)
{
const
element
=
array
[
i
];
if
(
compare
(
element
,
result
[
n
-
1
])
<
0
)
{
...
...
@@ -348,7 +348,7 @@ export function isNonEmptyArray<T>(obj: ReadonlyArray<T> | undefined | null): ob
* Removes duplicates from the given array. The optional keyFn allows to specify
* how elements are checked for equalness by returning a unique string for each.
*/
export
function
distinct
<
T
>
(
array
:
T
[]
,
keyFn
?:
(
t
:
T
)
=>
string
):
T
[]
{
export
function
distinct
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
keyFn
?:
(
t
:
T
)
=>
string
):
T
[]
{
if
(
!
keyFn
)
{
return
array
.
filter
((
element
,
position
)
=>
{
return
array
.
indexOf
(
element
)
===
position
;
...
...
@@ -383,7 +383,7 @@ export function uniqueFilter<T>(keyFn: (t: T) => string): (t: T) => boolean {
};
}
export
function
firstIndex
<
T
>
(
array
:
T
[]
|
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
):
number
{
export
function
firstIndex
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
):
number
{
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
const
element
=
array
[
i
];
...
...
@@ -395,14 +395,14 @@ export function firstIndex<T>(array: T[] | ReadonlyArray<T>, fn: (item: T) => bo
return
-
1
;
}
export
function
first
<
T
>
(
array
:
T
[]
|
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
,
notFoundValue
:
T
):
T
;
export
function
first
<
T
>
(
array
:
T
[]
|
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
):
T
|
null
;
export
function
first
<
T
>
(
array
:
T
[]
|
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
,
notFoundValue
:
T
|
null
=
null
):
T
|
null
{
export
function
first
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
,
notFoundValue
:
T
):
T
;
export
function
first
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
):
T
|
null
;
export
function
first
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
fn
:
(
item
:
T
)
=>
boolean
,
notFoundValue
:
T
|
null
=
null
):
T
|
null
{
const
index
=
firstIndex
(
array
,
fn
);
return
index
<
0
?
notFoundValue
:
array
[
index
];
}
export
function
commonPrefixLength
<
T
>
(
one
:
T
[],
other
:
T
[]
,
equals
:
(
a
:
T
,
b
:
T
)
=>
boolean
=
(
a
,
b
)
=>
a
===
b
):
number
{
export
function
commonPrefixLength
<
T
>
(
one
:
ReadonlyArray
<
T
>
,
other
:
ReadonlyArray
<
T
>
,
equals
:
(
a
:
T
,
b
:
T
)
=>
boolean
=
(
a
,
b
)
=>
a
===
b
):
number
{
let
result
=
0
;
for
(
let
i
=
0
,
len
=
Math
.
min
(
one
.
length
,
other
.
length
);
i
<
len
&&
equals
(
one
[
i
],
other
[
i
]);
i
++
)
{
...
...
@@ -451,9 +451,9 @@ export function fill<T>(num: number, valueFn: () => T, arr: T[] = []): T[] {
return
arr
;
}
export
function
index
<
T
>
(
array
:
T
[]
,
indexer
:
(
t
:
T
)
=>
string
):
{
[
key
:
string
]:
T
;
};
export
function
index
<
T
,
R
>
(
array
:
T
[]
,
indexer
:
(
t
:
T
)
=>
string
,
merger
?:
(
t
:
T
,
r
:
R
)
=>
R
):
{
[
key
:
string
]:
R
;
};
export
function
index
<
T
,
R
>
(
array
:
T
[]
,
indexer
:
(
t
:
T
)
=>
string
,
merger
:
(
t
:
T
,
r
:
R
)
=>
R
=
t
=>
t
as
any
):
{
[
key
:
string
]:
R
;
}
{
export
function
index
<
T
>
(
array
:
ReadonlyArray
<
T
>
,
indexer
:
(
t
:
T
)
=>
string
):
{
[
key
:
string
]:
T
;
};
export
function
index
<
T
,
R
>
(
array
:
ReadonlyArray
<
T
>
,
indexer
:
(
t
:
T
)
=>
string
,
merger
?:
(
t
:
T
,
r
:
R
)
=>
R
):
{
[
key
:
string
]:
R
;
};
export
function
index
<
T
,
R
>
(
array
:
ReadonlyArray
<
T
>
,
indexer
:
(
t
:
T
)
=>
string
,
merger
:
(
t
:
T
,
r
:
R
)
=>
R
=
t
=>
t
as
any
):
{
[
key
:
string
]:
R
;
}
{
return
array
.
reduce
((
r
,
t
)
=>
{
const
key
=
indexer
(
t
);
r
[
key
]
=
merger
(
t
,
r
[
key
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录