-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathcstl_hash_set_iterator.c
156 lines (127 loc) · 5.33 KB
/
cstl_hash_set_iterator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* The implementation of hash_set iterator.
* Copyright (C) 2008 - 2012 Wangbo
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author e-mail: activesys.wb@gmail.com
* activesys@sina.com.cn
*/
/** include section **/
#include <cstl/cstl_def.h>
#include <cstl/cstl_alloc.h>
#include <cstl/cstl_types.h>
#include <cstl/citerator.h>
#include <cstl/chash_set.h>
#include "cstl_hash_set_aux.h"
/** local constant declaration and local macro section **/
/** local data type declaration and local struct, union, enum section **/
/** local function prototype section **/
/** exported global variable definition section **/
/** local global variable definition section **/
/** exported function implementation section **/
/**
* Create hash_set iterator.
*/
hash_set_iterator_t create_hash_set_iterator(void)
{
hash_set_iterator_t it_iter = _create_hashtable_iterator();
_HASH_SET_ITERATOR_CONTAINER_TYPE(it_iter) = _HASH_SET_CONTAINER;
_HASH_SET_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;
return it_iter;
}
/**
* Get data value referenced by iterator.
*/
void _hash_set_iterator_get_value(hash_set_iterator_t it_iter, void* pv_value)
{
assert(pv_value != NULL);
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_iter) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_iter) == _BIDIRECTIONAL_ITERATOR);
_hashtable_iterator_get_value(it_iter, pv_value);
}
/**
* Get data value pointer referenced by iterator.
*/
const void* _hash_set_iterator_get_pointer(hash_set_iterator_t it_iter)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_iter) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_iter) == _BIDIRECTIONAL_ITERATOR);
return _hashtable_iterator_get_pointer(it_iter);
}
/**
* Get data value pointer referenced by iterator, but ignore char*.
*/
const void* _hash_set_iterator_get_pointer_ignore_cstr(hash_set_iterator_t it_iter)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_iter) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_iter) == _BIDIRECTIONAL_ITERATOR);
return _hashtable_iterator_get_pointer_ignore_cstr(it_iter);
}
/**
* Return iterator reference previous element.
*/
hash_set_iterator_t _hash_set_iterator_prev(hash_set_iterator_t it_iter)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_iter) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_iter) == _BIDIRECTIONAL_ITERATOR);
return _hashtable_iterator_prev(it_iter);
}
/**
* Return iterator reference next element.
*/
hash_set_iterator_t _hash_set_iterator_next(hash_set_iterator_t it_iter)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_iter) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_iter) == _BIDIRECTIONAL_ITERATOR);
return _hashtable_iterator_next(it_iter);
}
/**
* Test the two hash_set iterator are equal.
*/
bool_t _hash_set_iterator_equal(hash_set_iterator_t it_first, hash_set_iterator_t it_second)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_first) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_first) == _BIDIRECTIONAL_ITERATOR);
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_second) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_second) == _BIDIRECTIONAL_ITERATOR);
return _hashtable_iterator_equal(it_first, it_second);
}
/**
* Calculate distance between two iterators.
*/
int _hash_set_iterator_distance(hash_set_iterator_t it_first, hash_set_iterator_t it_second)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_first) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_first) == _BIDIRECTIONAL_ITERATOR);
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_second) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_second) == _BIDIRECTIONAL_ITERATOR);
assert(_HASH_SET_ITERATOR_CONTAINER(it_first) == _HASH_SET_ITERATOR_CONTAINER(it_second));
return _hashtable_iterator_distance(it_first, it_second);
}
/**
* Test the first iterator is before the second.
*/
bool_t _hash_set_iterator_before(hash_set_iterator_t it_first, hash_set_iterator_t it_second)
{
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_first) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_first) == _BIDIRECTIONAL_ITERATOR);
assert(_HASH_SET_ITERATOR_CONTAINER_TYPE(it_second) == _HASH_SET_CONTAINER);
assert(_HASH_SET_ITERATOR_ITERATOR_TYPE(it_second) == _BIDIRECTIONAL_ITERATOR);
assert(_HASH_SET_ITERATOR_CONTAINER(it_first) == _HASH_SET_ITERATOR_CONTAINER(it_second));
return _hashtable_iterator_before(it_first, it_second);
}
/** local function implementation section **/
/** eof **/