Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
7428746c
提交
7428746c
authored
4月 10, 2014
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-6453 --resolve
上级
7e9c3505
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
50 行增加
和
40 行删除
+50
-40
switch_hashtable.h
src/include/switch_hashtable.h
+2
-1
switch_core_hash.c
src/switch_core_hash.c
+1
-1
switch_hashtable.c
src/switch_hashtable.c
+47
-38
没有找到文件。
src/include/switch_hashtable.h
浏览文件 @
7428746c
...
@@ -119,7 +119,8 @@ switch_create_hashtable(switch_hashtable_t **hp, unsigned int minsize,
...
@@ -119,7 +119,8 @@ switch_create_hashtable(switch_hashtable_t **hp, unsigned int minsize,
typedef
enum
{
typedef
enum
{
HASHTABLE_FLAG_NONE
=
0
,
HASHTABLE_FLAG_NONE
=
0
,
HASHTABLE_FLAG_FREE_KEY
=
(
1
<<
0
),
HASHTABLE_FLAG_FREE_KEY
=
(
1
<<
0
),
HASHTABLE_FLAG_FREE_VALUE
=
(
1
<<
1
)
HASHTABLE_FLAG_FREE_VALUE
=
(
1
<<
1
),
HASHTABLE_DUP_CHECK
=
(
1
<<
2
)
}
hashtable_flag_t
;
}
hashtable_flag_t
;
SWITCH_DECLARE
(
int
)
SWITCH_DECLARE
(
int
)
...
...
src/switch_core_hash.c
浏览文件 @
7428746c
...
@@ -57,7 +57,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t **hash)
...
@@ -57,7 +57,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t **hash)
SWITCH_DECLARE
(
switch_status_t
)
switch_core_hash_insert_destructor
(
switch_hash_t
*
hash
,
const
char
*
key
,
const
void
*
data
,
hashtable_destructor_t
destructor
)
SWITCH_DECLARE
(
switch_status_t
)
switch_core_hash_insert_destructor
(
switch_hash_t
*
hash
,
const
char
*
key
,
const
void
*
data
,
hashtable_destructor_t
destructor
)
{
{
switch_hashtable_insert_destructor
(
hash
,
strdup
(
key
),
(
void
*
)
data
,
HASHTABLE_FLAG_FREE_KEY
,
destructor
);
switch_hashtable_insert_destructor
(
hash
,
strdup
(
key
),
(
void
*
)
data
,
HASHTABLE_FLAG_FREE_KEY
|
HASHTABLE_DUP_CHECK
,
destructor
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
...
src/switch_hashtable.c
浏览文件 @
7428746c
...
@@ -153,13 +153,54 @@ switch_hashtable_count(switch_hashtable_t *h)
...
@@ -153,13 +153,54 @@ switch_hashtable_count(switch_hashtable_t *h)
return
h
->
entrycount
;
return
h
->
entrycount
;
}
}
static
void
*
_switch_hashtable_remove
(
switch_hashtable_t
*
h
,
void
*
k
,
unsigned
int
hashvalue
,
unsigned
int
index
)
{
/* TODO: consider compacting the table when the load factor drops enough,
* or provide a 'compact' method. */
struct
entry
*
e
;
struct
entry
**
pE
;
void
*
v
;
pE
=
&
(
h
->
table
[
index
]);
e
=
*
pE
;
while
(
NULL
!=
e
)
{
/* Check hash value to short circuit heavier comparison */
if
((
hashvalue
==
e
->
h
)
&&
(
h
->
eqfn
(
k
,
e
->
k
)))
{
*
pE
=
e
->
next
;
h
->
entrycount
--
;
v
=
e
->
v
;
if
(
e
->
flags
&
HASHTABLE_FLAG_FREE_KEY
)
{
freekey
(
e
->
k
);
}
if
(
e
->
flags
&
HASHTABLE_FLAG_FREE_VALUE
)
{
switch_safe_free
(
e
->
v
);
v
=
NULL
;
}
else
if
(
e
->
destructor
)
{
e
->
destructor
(
e
->
v
);
v
=
e
->
v
=
NULL
;
}
switch_safe_free
(
e
);
return
v
;
}
pE
=
&
(
e
->
next
);
e
=
e
->
next
;
}
return
NULL
;
}
/*****************************************************************************/
/*****************************************************************************/
SWITCH_DECLARE
(
int
)
SWITCH_DECLARE
(
int
)
switch_hashtable_insert_destructor
(
switch_hashtable_t
*
h
,
void
*
k
,
void
*
v
,
hashtable_flag_t
flags
,
hashtable_destructor_t
destructor
)
switch_hashtable_insert_destructor
(
switch_hashtable_t
*
h
,
void
*
k
,
void
*
v
,
hashtable_flag_t
flags
,
hashtable_destructor_t
destructor
)
{
{
/* This method allows duplicate keys - but they shouldn't be used */
unsigned
int
index
;
struct
entry
*
e
;
struct
entry
*
e
;
unsigned
int
hashvalue
=
hash
(
h
,
k
);
unsigned
index
=
indexFor
(
h
->
tablelength
,
hashvalue
);
if
(
flags
&
HASHTABLE_DUP_CHECK
)
{
_switch_hashtable_remove
(
h
,
k
,
hashvalue
,
index
);
}
if
(
++
(
h
->
entrycount
)
>
h
->
loadlimit
)
if
(
++
(
h
->
entrycount
)
>
h
->
loadlimit
)
{
{
/* Ignore the return value. If expand fails, we should
/* Ignore the return value. If expand fails, we should
...
@@ -167,11 +208,11 @@ switch_hashtable_insert_destructor(switch_hashtable_t *h, void *k, void *v, hash
...
@@ -167,11 +208,11 @@ switch_hashtable_insert_destructor(switch_hashtable_t *h, void *k, void *v, hash
* -- we may not have memory for a larger table, but one more
* -- we may not have memory for a larger table, but one more
* element may be ok. Next time we insert, we'll try expanding again.*/
* element may be ok. Next time we insert, we'll try expanding again.*/
hashtable_expand
(
h
);
hashtable_expand
(
h
);
index
=
indexFor
(
h
->
tablelength
,
hashvalue
);
}
}
e
=
(
struct
entry
*
)
malloc
(
sizeof
(
struct
entry
));
e
=
(
struct
entry
*
)
malloc
(
sizeof
(
struct
entry
));
if
(
NULL
==
e
)
{
--
(
h
->
entrycount
);
return
0
;
}
/*oom*/
if
(
NULL
==
e
)
{
--
(
h
->
entrycount
);
return
0
;
}
/*oom*/
e
->
h
=
hash
(
h
,
k
);
e
->
h
=
hashvalue
;
index
=
indexFor
(
h
->
tablelength
,
e
->
h
);
e
->
k
=
k
;
e
->
k
=
k
;
e
->
v
=
v
;
e
->
v
=
v
;
e
->
flags
=
flags
;
e
->
flags
=
flags
;
...
@@ -202,40 +243,8 @@ switch_hashtable_search(switch_hashtable_t *h, void *k)
...
@@ -202,40 +243,8 @@ switch_hashtable_search(switch_hashtable_t *h, void *k)
SWITCH_DECLARE
(
void
*
)
/* returns value associated with key */
SWITCH_DECLARE
(
void
*
)
/* returns value associated with key */
switch_hashtable_remove
(
switch_hashtable_t
*
h
,
void
*
k
)
switch_hashtable_remove
(
switch_hashtable_t
*
h
,
void
*
k
)
{
{
/* TODO: consider compacting the table when the load factor drops enough,
unsigned
int
hashvalue
=
hash
(
h
,
k
);
* or provide a 'compact' method. */
return
_switch_hashtable_remove
(
h
,
k
,
hashvalue
,
indexFor
(
h
->
tablelength
,
hashvalue
));
struct
entry
*
e
;
struct
entry
**
pE
;
void
*
v
;
unsigned
int
hashvalue
,
index
;
hashvalue
=
hash
(
h
,
k
);
index
=
indexFor
(
h
->
tablelength
,
hashvalue
);
pE
=
&
(
h
->
table
[
index
]);
e
=
*
pE
;
while
(
NULL
!=
e
)
{
/* Check hash value to short circuit heavier comparison */
if
((
hashvalue
==
e
->
h
)
&&
(
h
->
eqfn
(
k
,
e
->
k
)))
{
*
pE
=
e
->
next
;
h
->
entrycount
--
;
v
=
e
->
v
;
if
(
e
->
flags
&
HASHTABLE_FLAG_FREE_KEY
)
{
freekey
(
e
->
k
);
}
if
(
e
->
flags
&
HASHTABLE_FLAG_FREE_VALUE
)
{
switch_safe_free
(
e
->
v
);
}
else
if
(
e
->
destructor
)
{
e
->
destructor
(
e
->
v
);
e
->
v
=
NULL
;
}
switch_safe_free
(
e
);
return
v
;
}
pE
=
&
(
e
->
next
);
e
=
e
->
next
;
}
return
NULL
;
}
}
/*****************************************************************************/
/*****************************************************************************/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论