| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Native Client Authors. All rights reserved. | 2 * Copyright 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Generic containers. | 8 * NaCl Generic containers. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef NATIVE_CLIENT_GENERIC_CONTAINER_CONTAINER_H_ | 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_GENERIC_CONTAINER_CONTAINER_H_ |
| 12 #define NATIVE_CLIENT_GENERIC_CONTAINER_CONTAINER_H_ | 12 #define NATIVE_CLIENT_SRC_TRUSTED_GENERIC_CONTAINER_CONTAINER_H_ |
| 13 | |
| 14 #include <sys/types.h> | |
| 15 | 13 |
| 16 #include "native_client/src/include/nacl_base.h" | 14 #include "native_client/src/include/nacl_base.h" |
| 15 #include "native_client/src/include/portability.h" |
| 17 | 16 |
| 18 EXTERN_C_BEGIN | 17 EXTERN_C_BEGIN |
| 19 | 18 |
| 20 struct NaClCmpFunctorVtbl; | 19 struct NaClCmpFunctorVtbl; |
| 21 | 20 |
| 22 struct NaClCmpFunctor { | 21 struct NaClCmpFunctor { |
| 23 struct NaClCmpFunctorVtbl *vtbl; | 22 struct NaClCmpFunctorVtbl *vtbl; |
| 24 }; | 23 }; |
| 25 | 24 |
| 26 /** | 25 /** |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void (*Incr)(struct NaClContainerIter *vself); | 86 void (*Incr)(struct NaClContainerIter *vself); |
| 88 void (*Erase)(struct NaClContainerIter *vself); | 87 void (*Erase)(struct NaClContainerIter *vself); |
| 89 void *(*Extract)(struct NaClContainerIter *vself); | 88 void *(*Extract)(struct NaClContainerIter *vself); |
| 90 /* like erase, but takes ownership back, so no automatic free */ | 89 /* like erase, but takes ownership back, so no automatic free */ |
| 91 }; | 90 }; |
| 92 | 91 |
| 93 struct NaClContainerIter { | 92 struct NaClContainerIter { |
| 94 struct NaClContainerIterVtbl const *vtbl; | 93 struct NaClContainerIterVtbl const *vtbl; |
| 95 }; | 94 }; |
| 96 | 95 |
| 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 | 96 EXTERN_C_END |
| 177 | 97 |
| 178 #endif | 98 #endif /* NATIVE_CLIENT_SRC_TRUSTED_GENERIC_CONTAINER_CONTAINER_H_ */ |
| OLD | NEW |