Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: src/trusted/service_runtime/generic_container/container.h

Issue 10905317: Generic containers moved into a separate module (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Rebased with master. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file.
5 */
6
7 /*
8 * NaCl Generic containers.
9 */
10
11 #ifndef NATIVE_CLIENT_GENERIC_CONTAINER_CONTAINER_H_
12 #define NATIVE_CLIENT_GENERIC_CONTAINER_CONTAINER_H_
13
14 #include <sys/types.h>
15
16 #include "native_client/src/include/nacl_base.h"
17
18 EXTERN_C_BEGIN
19
20 struct NaClCmpFunctorVtbl;
21
22 struct NaClCmpFunctor {
23 struct NaClCmpFunctorVtbl *vtbl;
24 };
25
26 /**
27 * OrderCmp should return 0 if objects are equal (so a 3-way compare
28 * function that might be used for a tree container may be re-used
29 * here).
30 */
31 struct NaClCmpFunctorVtbl {
32 void (*Dtor)(struct NaClCmpFunctor *vself);
33 int (*OrderCmp)(struct NaClCmpFunctor *vself,
34 void *left,
35 void *right);
36 };
37
38 struct NaClHashFunctorVtbl;
39
40 struct NaClHashFunctor {
41 struct NaClHashFunctorVtbl const *vtbl;
42 };
43
44 struct NaClHashFunctorVtbl {
45 struct NaClCmpFunctorVtbl base;
46 uintptr_t (*Hash)(struct NaClHashFunctor *vself,
47 void *datum);
48 };
49
50 struct NaClContainer; /* fwd */
51
52 struct NaClContainerIter; /* fwd */
53
54 struct NaClContainerVtbl {
55 /*
56 * Insert passes ownership of obj to the container; obj must be
57 * malloc'd.
58 */
59 int (*Insert)(struct NaClContainer *vself,
60 void *obj);
61 /*
62 * Find: if returned/constructed iterator is not AtEnd, can Star it
63 * to access datum, then Erase the entry to free it. Erase
64 * implicitly increments the iterator. The out parameter should be
65 * a pointer to an object of the appropriate subclass of
66 * ContainerIter to be constructed. It can be malloc'd/aligned
67 * memory of iter_size bytes in size; the iterator will be placement
68 * new'd in the memory. All iterator objects are POD, so the dtor
69 * is a no-op.
70 */
71 struct NaClContainerIter *(*Find)(struct NaClContainer *vself,
72 void *key,
73 struct NaClContainerIter *out);
74 void (*Dtor)(struct NaClContainer *vself);
75 size_t iter_size;
76 int (*IterCtor)(struct NaClContainer *vself,
77 struct NaClContainerIter *iter);
78 };
79
80 struct NaClContainer {
81 struct NaClContainerVtbl const *vtbl;
82 };
83
84 struct NaClContainerIterVtbl {
85 int (*AtEnd)(struct NaClContainerIter *vself);
86 void *(*Star)(struct NaClContainerIter *vself);
87 void (*Incr)(struct NaClContainerIter *vself);
88 void (*Erase)(struct NaClContainerIter *vself);
89 void *(*Extract)(struct NaClContainerIter *vself);
90 /* like erase, but takes ownership back, so no automatic free */
91 };
92
93 struct NaClContainerIter {
94 struct NaClContainerIterVtbl const *vtbl;
95 };
96
97 /* linked list */
98
99 struct NaClItemList {
100 struct NaClItemList *next;
101 void *datum; /* dynamically allocated, pod */
102 };
103
104 struct NaClContainerList {
105 struct NaClContainer base;
106 struct NaClCmpFunctor *cmp_functor;
107 struct NaClItemList *head;
108 };
109
110 int NaClContainerListCtor(struct NaClContainerList *clp,
111 struct NaClCmpFunctor *cmp_functor);
112
113 int NaClContainerListInsert(struct NaClContainer *base_pointer,
114 void *obj);
115
116 struct NaClContainerIter *NaClContainerListFind(
117 struct NaClContainer *base_pointer,
118 void *key,
119 struct NaClContainerIter *out);
120
121 void NaClContainerListDtor(struct NaClContainer *vself);
122
123 struct NaClContainerListIter {
124 struct NaClContainerIter base;
125 struct NaClItemList **cur;
126 };
127
128 int NaClContainerListIterCtor(struct NaClContainer *vself,
129 struct NaClContainerIter *viter);
130
131 /* hash table */
132
133 struct NaClContainerHashTblEntry {
134 int flags;
135 void *datum;
136 };
137
138 #define NACL_CHTE_USED (1<<0)
139 /* slot occupied, so keep probing */
140
141 #define NACL_CHTE_DELETED (1<<1)
142 /* slot occupied but deleted, keep probing */
143
144 struct NaClContainerHashTbl {
145 struct NaClContainer base;
146 struct NaClHashFunctor *hash_functor;
147 size_t num_buckets;
148 size_t num_entries;
149 struct NaClContainerHashTblEntry *bucket;
150 };
151
152 int NaClContainerHashTblCtor(struct NaClContainerHashTbl *self,
153 struct NaClHashFunctor *hash_functor,
154 size_t num_buckets);
155
156 int NaClContainerHashTblInsert(struct NaClContainer *vself,
157 void *obj);
158
159 struct NaClContainerIter *NaClContainerHashTblFind(
160 struct NaClContainer *vself,
161 void *key,
162 struct NaClContainerIter *out);
163
164 void NaClContainerHashTblDtor(struct NaClContainer *vself);
165
166 struct NaClContainerHashTblIter {
167 struct NaClContainerIter base;
168 struct NaClContainerHashTbl *htbl;
169 uintptr_t idx;
170 };
171
172 int NaClContainerHashTblIterCtor(struct NaClContainer *vself,
173 struct NaClContainerIter *viter);
174
175
176 EXTERN_C_END
177
178 #endif
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/build.scons ('k') | src/trusted/service_runtime/generic_container/container.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698