xref: /OK3568_Linux_fs/external/security/rk_tee_user/v2/ta/vector_util/c_map.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * Copyright (c) 1994
4  * Hewlett-Packard Company
5  *
6  * Permission to use, copy, modify, distribute and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.  Hewlett-Packard Company makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  *
15  * Copyright (c) 1996
16  * Silicon Graphics Computer Systems, Inc.
17  *
18  * Permission to use, copy, modify, distribute and sell this software
19  * and its documentation for any purpose is hereby granted without fee,
20  * provided that the above copyright notice appear in all copies and
21  * that both that copyright notice and this permission notice appear
22  * in supporting documentation.  Silicon Graphics makes no
23  * representations about the suitability of this software for any
24  * purpose.  It is provided "as is" without express or implied warranty.
25  */
26 
27 /*
28 Copyright (c) 2007 Lao wen bo
29 
30 This software is provided 'as-is', without any express or implied
31 warranty. In no event will the authors be held liable for any damages
32 arising from the use of this software.
33 
34 Permission is granted to anyone to use this software for any purpose,
35 including commercial applications, and to alter it and redistribute it
36 freely, subject to the following restrictions:
37 
38     1. The origin of this software must not be misrepresented; you must not
39     claim that you wrote the original software. If you use this software
40     in a product, an acknowledgment in the product documentation would be
41     appreciated but is not required.
42 
43     2. Altered source versions must be plainly marked as such, and must not be
44     misrepresented as being the original software.
45 
46     3. This notice may not be removed or altered from any source
47     distribution.
48 
49 	Lao wen bo
50 	viewpl(at)gmail.com
51  */
52 
53 #include "c_map.h"
54 
__c_map(c_pmap thiz,COMPARER keycmp)55 void __c_map(c_pmap thiz, COMPARER keycmp)
56 {
57 	c_prb_tree ptree = (c_prb_tree)__c_malloc(sizeof(c_rb_tree));
58 	__c_rb_tree(ptree, keycmp);
59 	ptree->_A_keyofvalue = c_select1st();
60 	thiz->_l = ptree;
61 }
62 
__c_pam(c_pmap thiz)63 void __c_pam(c_pmap thiz)
64 {
65 	__c_eert_br((c_prb_tree)thiz->_l);
66 	__c_free(thiz->_l);
67 }
68 
c_map_assign(c_pmap thiz,const c_pmap M)69 c_pmap c_map_assign(c_pmap thiz, const c_pmap M)
70 {
71 	c_rb_tree_assign((c_prb_tree)thiz->_l, (c_prb_tree)M->_l);
72 	return thiz;
73 }
74 
c_map_begin(c_pmap thiz)75 c_iterator c_map_begin(c_pmap thiz)
76 {
77 	return c_rb_tree_begin((c_prb_tree)thiz->_l);
78 }
79 
c_map_end(c_pmap thiz)80 c_iterator c_map_end(c_pmap thiz)
81 {
82 	return c_rb_tree_end((c_prb_tree)thiz->_l);
83 }
84 
c_map_rbegin(c_pmap thiz)85 c_reverse_iterator c_map_rbegin(c_pmap thiz)
86 {
87 	return c_rb_tree_rbegin((c_prb_tree)thiz->_l);
88 }
89 
c_map_rend(c_pmap thiz)90 c_reverse_iterator c_map_rend(c_pmap thiz)
91 {
92 	return c_rb_tree_rend((c_prb_tree)thiz->_l);
93 }
94 
c_map_empty(c_pmap thiz)95 c_bool c_map_empty(c_pmap thiz)
96 {
97 	return c_rb_tree_empty((c_prb_tree)thiz->_l);
98 }
99 
c_map_size(c_pmap thiz)100 size_type c_map_size(c_pmap thiz)
101 {
102 	return c_rb_tree_size((c_prb_tree)thiz->_l);
103 }
104 
c_map_max_size(c_pmap thiz)105 size_type c_map_max_size(c_pmap thiz)
106 {
107 	return c_rb_tree_max_size((c_prb_tree)thiz->_l);
108 }
109 
c_map_at(c_pmap thiz,key_type key)110 value_type c_map_at(c_pmap thiz, key_type key)
111 {
112 	c_iterator iter = c_map_lower_bound(thiz, key);
113 	c_iterator end = c_map_end(thiz);
114 	if(ITER_EQUAL(iter, end) ||
115 		((c_prb_tree)thiz->_l)->_A_key_compare(key,
116 						       ((c_ppair)ITER_REF(iter))->first) < 0)
117 		return NULL;	/* difference between STL */
118 	return ((c_ppair)ITER_REF(iter))->second;
119 }
120 
c_map_swap(c_pmap thiz,c_pmap M)121 void c_map_swap(c_pmap thiz, c_pmap M)
122 {
123 	c_rb_tree_swap((c_prb_tree)thiz->_l, (c_prb_tree)M->_l);
124 }
125 
c_map_insert(c_pmap thiz,const value_type val)126 c_iter_bool_pair c_map_insert(c_pmap thiz, const value_type val)
127 {
128 	return c_rb_tree_insert_unique((c_prb_tree)thiz->_l, val);
129 }
130 
c_map_insert1(c_pmap thiz,c_iterator position,const value_type val)131 c_iterator c_map_insert1(c_pmap thiz, c_iterator position, const value_type val)
132 {
133 	return c_rb_tree_insert_unique1((c_prb_tree)thiz->_l, position, val);
134 }
135 
c_map_insert2(c_pmap thiz,c_iterator first,c_iterator last)136 void c_map_insert2(c_pmap thiz, c_iterator first, c_iterator last)
137 {
138 	c_rb_tree_insert_unique2((c_prb_tree)thiz->_l, first, last);
139 }
140 
c_map_erase(c_pmap thiz,c_iterator position)141 void c_map_erase(c_pmap thiz, c_iterator position)
142 {
143 	c_rb_tree_erase((c_prb_tree)thiz->_l, position);
144 }
145 
c_map_erase1(c_pmap thiz,key_type key)146 size_type c_map_erase1(c_pmap thiz, key_type key)
147 {
148 	return c_rb_tree_erase1((c_prb_tree)thiz->_l, key);
149 }
150 
c_map_erase2(c_pmap thiz,c_iterator first,c_iterator last)151 void c_map_erase2(c_pmap thiz, c_iterator first, c_iterator last)
152 {
153 	c_rb_tree_erase2((c_prb_tree)thiz->_l, first, last);
154 }
155 
c_map_clear(c_pmap thiz)156 void c_map_clear(c_pmap thiz)
157 {
158 	c_rb_tree_clear((c_prb_tree)thiz->_l);
159 }
160 
c_map_find(c_pmap thiz,key_type key)161 c_iterator c_map_find(c_pmap thiz, key_type key)
162 {
163 	return c_rb_tree_find((c_prb_tree)thiz->_l, key);
164 }
165 
c_map_count(c_pmap thiz,key_type key)166 size_type c_map_count(c_pmap thiz, key_type key)
167 {
168 	c_iterator key_iter = c_rb_tree_find((c_prb_tree)thiz->_l, key);
169 	c_iterator end = c_rb_tree_end((c_prb_tree)thiz->_l);
170 	return ITER_EQUAL(key_iter, end) ? 0 : 1;
171 }
172 
c_map_lower_bound(c_pmap thiz,key_type key)173 c_iterator c_map_lower_bound(c_pmap thiz, key_type key)
174 {
175 	return c_rb_tree_lower_bound((c_prb_tree)thiz->_l, key);
176 }
177 
c_map_upper_bound(c_pmap thiz,key_type key)178 c_iterator c_map_upper_bound(c_pmap thiz, key_type key)
179 {
180 	return c_rb_tree_upper_bound((c_prb_tree)thiz->_l, key);
181 }
182 
c_map_equal_range(c_pmap thiz,key_type key)183 c_iter_iter_pair c_map_equal_range(c_pmap thiz, key_type key)
184 {
185 	return c_rb_tree_equal_range((c_prb_tree)thiz->_l, key);
186 }
187 
c_map_less(c_pmap thiz,const c_pmap M,COMPARER paircmp)188 c_bool c_map_less(c_pmap thiz, const c_pmap M, COMPARER paircmp)
189 {
190 	return c_rb_tree_less((c_prb_tree)thiz->_l, (c_prb_tree)M->_l, paircmp);
191 }
192 
c_map_equal(c_pmap thiz,const c_pmap M,COMPARER paircmp)193 c_bool c_map_equal(c_pmap thiz, const c_pmap M, COMPARER paircmp)
194 {
195 	return c_rb_tree_equal((c_prb_tree)thiz->_l, (c_prb_tree)M->_l, paircmp);
196 }
197 
198