Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
77bcf6b5
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
77bcf6b5
编写于
11月 15, 2006
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added several iterators to hashtable API
上级
678073a2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
164 addition
and
1 deletion
+164
-1
ChangeLog
ChangeLog
+6
-0
src/hash.c
src/hash.c
+129
-0
src/hash.h
src/hash.h
+29
-1
未找到文件。
ChangeLog
浏览文件 @
77bcf6b5
Wed Nov 15 15:59:13 EST 2006 Daniel Berrange <berrange@redhat.com>
* src/hash.c, src/hash.h: Added three new methods for iterating
over hashtable entries, virHashForEach, virHashRemoveSet &
virHashSearch.
Wed Nov 15 15:52:01 EST 2006 Daniel Berrange <berrange@redhat.com>
* src/conf.c, src/conf.h: Add two new APIs virConfNew() and
...
...
src/hash.c
浏览文件 @
77bcf6b5
...
...
@@ -473,6 +473,127 @@ virHashRemoveEntry(virHashTablePtr table, const char *name,
}
}
/**
* virHashForEach
* @table: the hash table to process
* @iter: callback to process each element
* @data: opaque data to pass to the iterator
*
* Iterates over every element in the hash table, invoking the
* 'iter' callback. The callback must not call any other virHash*
* functions, and in particular must not attempt to remove the
* element.
*
* Returns number of items iterated over upon completion, -1 on failure
*/
int
virHashForEach
(
virHashTablePtr
table
,
virHashIterator
iter
,
const
void
*
data
)
{
int
i
,
count
=
0
;
if
(
table
==
NULL
||
iter
==
NULL
)
return
(
-
1
);
for
(
i
=
0
;
i
<
table
->
size
;
i
++
)
{
virHashEntryPtr
entry
=
table
->
table
+
i
;
while
(
entry
)
{
if
(
entry
->
valid
)
{
iter
(
entry
->
payload
,
entry
->
name
,
data
);
count
++
;
}
entry
=
entry
->
next
;
}
}
return
(
count
);
}
/**
* virHashRemoveSet
* @table: the hash table to process
* @iter: callback to identify elements for removal
* @f: callback to free memory from element payload
* @data: opaque data to pass to the iterator
*
* Iterates over all elements in the hash table, invoking the 'iter'
* callback. If the callback returns a non-zero value, the element
* will be removed from the hash table & its payload passed to the
* callback 'f' for de-allocation.
*
* Returns number of items removed on success, -1 on failure
*/
int
virHashRemoveSet
(
virHashTablePtr
table
,
virHashSearcher
iter
,
virHashDeallocator
f
,
const
void
*
data
)
{
int
i
,
count
=
0
;
if
(
table
==
NULL
||
iter
==
NULL
)
return
(
-
1
);
for
(
i
=
0
;
i
<
table
->
size
;
i
++
)
{
virHashEntryPtr
prev
=
NULL
;
virHashEntryPtr
entry
=
&
(
table
->
table
[
i
]);
while
(
entry
&&
entry
->
valid
)
{
if
(
iter
(
entry
->
payload
,
entry
->
name
,
data
))
{
count
++
;
f
(
entry
->
payload
,
entry
->
name
);
if
(
entry
->
name
)
free
(
entry
->
name
);
if
(
prev
)
{
prev
->
next
=
entry
->
next
;
free
(
entry
);
}
else
{
if
(
entry
->
next
==
NULL
)
{
entry
->
valid
=
0
;
entry
->
name
=
NULL
;
}
else
{
entry
=
entry
->
next
;
memcpy
(
&
(
table
->
table
[
i
]),
entry
,
sizeof
(
virHashEntry
));
free
(
entry
);
entry
=
NULL
;
}
}
table
->
nbElems
--
;
}
prev
=
entry
;
if
(
entry
)
{
entry
=
entry
->
next
;
}
else
{
entry
=
NULL
;
}
}
}
return
(
count
);
}
/**
* virHashSearch:
* @table: the hash table to search
* @iter: an iterator to identify the desired element
* @data: extra opaque information passed to the iter
*
* Iterates over the hash table calling the 'iter' callback
* for each element. The first element for which the iter
* returns non-zero will be returned by this function.
* The elements are processed in a undefined order
*/
void
*
virHashSearch
(
virHashTablePtr
table
,
virHashSearcher
iter
,
const
void
*
data
)
{
int
i
;
if
(
table
==
NULL
||
iter
==
NULL
)
return
(
NULL
);
for
(
i
=
0
;
i
<
table
->
size
;
i
++
)
{
virHashEntryPtr
entry
=
table
->
table
+
i
;
while
(
entry
)
{
if
(
entry
->
valid
)
{
if
(
iter
(
entry
->
payload
,
entry
->
name
,
data
))
return
entry
->
payload
;
}
entry
=
entry
->
next
;
}
}
return
(
NULL
);
}
/************************************************************************
* *
* Domain and Connections allocations *
...
...
@@ -770,3 +891,11 @@ done:
xmlMutexUnlock
(
conn
->
domains_mux
);
return
(
ret
);
}
/*
* Local variables:
* indent-tabs-mode: nil
* c-indent-level: 4
* c-basic-offset: 4
* tab-width: 4
* End:
*/
src/hash.h
浏览文件 @
77bcf6b5
...
...
@@ -33,7 +33,27 @@ typedef virHashTable *virHashTablePtr;
*
* Callback to free data from a hash.
*/
typedef
void
(
*
virHashDeallocator
)
(
void
*
payload
,
char
*
name
);
typedef
void
(
*
virHashDeallocator
)
(
void
*
payload
,
const
char
*
name
);
/**
* virHashIterator:
* @payload: the data in the hash
* @name: the name associated
* @data: user supplied data blob
*
* Callback to process a hash entry during iteration
*/
typedef
void
(
*
virHashIterator
)
(
const
void
*
payload
,
const
char
*
name
,
const
void
*
data
);
/**
* virHashSearcher
* @payload: the data in the hash
* @name: the name associated
* @data: user supplied data blob
*
* Callback to identify hash entry desired
* Returns 1 if the hash entry is desired, 0 to move
* to next entry
*/
typedef
int
(
*
virHashSearcher
)
(
const
void
*
payload
,
const
char
*
name
,
const
void
*
data
);
/*
* Constructor and destructor.
...
...
@@ -62,6 +82,14 @@ int virHashRemoveEntry(virHashTablePtr table,
*/
void
*
virHashLookup
(
virHashTablePtr
table
,
const
char
*
name
);
/*
* Iterators
*/
int
virHashForEach
(
virHashTablePtr
table
,
virHashIterator
iter
,
const
void
*
data
);
int
virHashRemoveSet
(
virHashTablePtr
table
,
virHashSearcher
iter
,
virHashDeallocator
f
,
const
void
*
data
);
void
*
virHashSearch
(
virHashTablePtr
table
,
virHashSearcher
iter
,
const
void
*
data
);
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录