Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
c98f51da
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
接近 2 年 前同步成功
通知
1
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c98f51da
编写于
3月 30, 2019
作者:
B
Behdad Esfahbod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[map] Templatize hb_map_t
Template name is hb_hashmap_t<K,V>.
上级
4b7f4dbc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
28 deletion
+37
-28
src/hb-map.hh
src/hb-map.hh
+37
-28
未找到文件。
src/hb-map.hh
浏览文件 @
c98f51da
...
...
@@ -31,22 +31,28 @@
/*
* hb_map_t
* hb_
hash
map_t
*/
struct
hb_map_t
template
<
typename
K
,
typename
V
,
K
kINVALID
=
hb_is_pointer
(
K
)
?
0
:
(
K
)
-
1
,
V
vINVALID
=
hb_is_pointer
(
V
)
?
0
:
(
V
)
-
1
>
struct
hb_hashmap_t
{
HB_NO_COPY_ASSIGN
(
hb_map_t
);
hb_map_t
()
{
init
();
}
~
hb_map_t
()
{
fini
();
}
HB_NO_COPY_ASSIGN
(
hb_hashmap_t
);
hb_hashmap_t
()
{
init
();
}
~
hb_hashmap_t
()
{
fini
();
}
static_assert
(
hb_is_integer
(
K
)
||
hb_is_pointer
(
K
),
""
);
static_assert
(
hb_is_integer
(
V
)
||
hb_is_pointer
(
V
),
""
);
struct
item_t
{
hb_codepoint_t
key
;
hb_codepoint_t
value
;
K
key
;
V
value
;
bool
is_unused
()
const
{
return
key
==
INVALID
;
}
bool
is_tombstone
()
const
{
return
key
!=
INVALID
&&
value
==
INVALID
;
}
bool
is_unused
()
const
{
return
key
==
k
INVALID
;
}
bool
is_tombstone
()
const
{
return
key
!=
kINVALID
&&
value
==
v
INVALID
;
}
};
hb_object_header_t
header
;
...
...
@@ -110,7 +116,7 @@ struct hb_map_t
/* Insert back old items. */
if
(
old_items
)
for
(
unsigned
int
i
=
0
;
i
<
old_size
;
i
++
)
if
(
old_items
[
i
].
key
!=
INVALID
&&
old_items
[
i
].
value
!=
INVALID
)
if
(
old_items
[
i
].
key
!=
kINVALID
&&
old_items
[
i
].
value
!=
v
INVALID
)
set
(
old_items
[
i
].
key
,
old_items
[
i
].
value
);
free
(
old_items
);
...
...
@@ -118,14 +124,14 @@ struct hb_map_t
return
true
;
}
void
set
(
hb_codepoint_t
key
,
hb_codepoint_t
value
)
void
set
(
K
key
,
V
value
)
{
if
(
unlikely
(
!
successful
))
return
;
if
(
unlikely
(
key
==
INVALID
))
return
;
if
(
unlikely
(
key
==
k
INVALID
))
return
;
if
((
occupancy
+
occupancy
/
2
)
>=
mask
&&
!
resize
())
return
;
unsigned
int
i
=
bucket_for
(
key
);
if
(
value
==
INVALID
&&
items
[
i
].
key
!=
key
)
if
(
value
==
v
INVALID
&&
items
[
i
].
key
!=
key
)
return
;
/* Trying to delete non-existent key. */
if
(
!
items
[
i
].
is_unused
())
...
...
@@ -143,24 +149,22 @@ struct hb_map_t
population
++
;
}
hb_codepoint_t
get
(
hb_codepoint_t
key
)
const
V
get
(
K
key
)
const
{
if
(
unlikely
(
!
items
))
return
INVALID
;
if
(
unlikely
(
!
items
))
return
v
INVALID
;
unsigned
int
i
=
bucket_for
(
key
);
return
items
[
i
].
key
==
key
?
items
[
i
].
value
:
INVALID
;
return
items
[
i
].
key
==
key
?
items
[
i
].
value
:
v
INVALID
;
}
void
del
(
hb_codepoint_t
key
)
{
set
(
key
,
INVALID
);
}
static
constexpr
hb_codepoint_t
INVALID
=
HB_MAP_VALUE_INVALID
;
void
del
(
K
key
)
{
set
(
key
,
vINVALID
);
}
/* Has interface. */
static
constexpr
hb_codepoint_t
SENTINEL
=
INVALID
;
typedef
hb_codepoint_t
value_t
;
value_t
operator
[]
(
hb_codepoint_t
k
)
const
{
return
get
(
k
);
}
bool
has
(
hb_codepoint_t
k
)
const
{
return
(
*
this
)[
k
]
!=
SENTINEL
;
}
static
constexpr
V
SENTINEL
=
v
INVALID
;
typedef
V
value_t
;
value_t
operator
[]
(
K
k
)
const
{
return
get
(
k
);
}
bool
has
(
K
k
)
const
{
return
(
*
this
)[
k
]
!=
SENTINEL
;
}
/* Projection. */
hb_codepoint_t
operator
()
(
hb_codepoint_t
k
)
const
{
return
get
(
k
);
}
V
operator
()
(
K
k
)
const
{
return
get
(
k
);
}
void
clear
()
{
...
...
@@ -174,20 +178,20 @@ struct hb_map_t
protected:
unsigned
int
bucket_for
(
hb_codepoint_t
key
)
const
unsigned
int
bucket_for
(
K
key
)
const
{
unsigned
int
i
=
hb_hash
(
key
)
%
prime
;
unsigned
int
step
=
0
;
unsigned
int
tombstone
=
INVALID
;
unsigned
int
tombstone
=
(
unsigned
)
-
1
;
while
(
!
items
[
i
].
is_unused
())
{
if
(
items
[
i
].
key
==
key
)
return
i
;
if
(
tombstone
==
INVALID
&&
items
[
i
].
is_tombstone
())
if
(
tombstone
==
(
unsigned
)
-
1
&&
items
[
i
].
is_tombstone
())
tombstone
=
i
;
i
=
(
i
+
++
step
)
&
mask
;
}
return
tombstone
==
INVALID
?
i
:
tombstone
;
return
tombstone
==
(
unsigned
)
-
1
?
i
:
tombstone
;
}
static
unsigned
int
prime_for
(
unsigned
int
shift
)
...
...
@@ -242,5 +246,10 @@ struct hb_map_t
}
};
struct
hb_map_t
:
hb_hashmap_t
<
hb_codepoint_t
,
hb_codepoint_t
,
HB_MAP_VALUE_INVALID
,
HB_MAP_VALUE_INVALID
>
{};
#endif
/* HB_MAP_HH */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录