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

Unified Diff: src/trusted/generic_container/container_hash_table.c

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 side-by-side diff with in-line comments
Download patch
Index: src/trusted/generic_container/container_hash_table.c
diff --git a/src/trusted/service_runtime/generic_container/container.c b/src/trusted/generic_container/container_hash_table.c
similarity index 67%
rename from src/trusted/service_runtime/generic_container/container.c
rename to src/trusted/generic_container/container_hash_table.c
index ec4d67b8bf23a728d507158d1d47fa8b769c6c60..9497eaf7b68b98a49702f64354ecffd4171cf8f3 100644
--- a/src/trusted/service_runtime/generic_container/container.c
+++ b/src/trusted/generic_container/container_hash_table.c
@@ -4,164 +4,9 @@
* be found in the LICENSE file.
*/
-/*
- * NaCl Generic containers.
- */
-#include "native_client/src/include/portability.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "native_client/src/trusted/service_runtime/generic_container/container.h"
-
-static struct NaClContainerVtbl const kNaClContainerListVtbl = {
- NaClContainerListInsert,
- NaClContainerListFind,
- NaClContainerListDtor,
- sizeof(struct NaClContainerListIter),
- NaClContainerListIterCtor,
-};
-
-
-/*
- * functor_obj is the comparison functor, and is the first argument to
- * cmp_fn as the "self" (or more commonly "this") argument. arguably
- * we should create an explicit object with a vtable containing the
- * single comparison function pointer, but this is so simple that that
- * seems overkill.
- */
-int NaClContainerListCtor(struct NaClContainerList *self,
- struct NaClCmpFunctor *cmp_functor) {
- self->cmp_functor = cmp_functor;
- self->head = 0;
-
- self->base.vtbl = &kNaClContainerListVtbl;
- return 1;
-}
-
-
-int NaClContainerListIterAtEnd(struct NaClContainerIter *vself) {
- struct NaClContainerListIter *self = (struct NaClContainerListIter *) vself;
-
- return *self->cur == 0;
-}
-
-
-void *NaClContainerListIterStar(struct NaClContainerIter *vself) {
- struct NaClContainerListIter *self = (struct NaClContainerListIter *) vself;
-
- return (*self->cur)->datum;
-}
-
-
-void NaClContainerListIterIncr(struct NaClContainerIter *vself) {
- struct NaClContainerListIter *self = (struct NaClContainerListIter *) vself;
-
- self->cur = &(*self->cur)->next;
-}
-
-
-void NaClContainerListIterErase(struct NaClContainerIter *vself) {
- struct NaClContainerListIter *self = (struct NaClContainerListIter *) vself;
- struct NaClItemList *doomed = *self->cur;
- struct NaClItemList *next = (*self->cur)->next;
-
- *self->cur = next;
- free(doomed->datum);
- free(doomed);
-}
-
-
-void *NaClContainerListIterExtract(struct NaClContainerIter *vself) {
- struct NaClContainerListIter *self = (struct NaClContainerListIter *) vself;
- struct NaClItemList *doomed = *self->cur;
- struct NaClItemList *next = (*self->cur)->next;
- void *datum;
-
- *self->cur = next;
- datum = doomed->datum;
- free(doomed);
- return datum;
-}
-
-static struct NaClContainerIterVtbl const kNaClContainerListIterVtbl = {
- NaClContainerListIterAtEnd,
- NaClContainerListIterStar,
- NaClContainerListIterIncr,
- NaClContainerListIterErase,
- NaClContainerListIterExtract,
-};
-
-
-int NaClContainerListInsert(struct NaClContainer *vself,
- void *obj) {
- struct NaClContainerList *self = (struct NaClContainerList *) vself;
- struct NaClItemList *new_entry = malloc(sizeof *new_entry);
- struct NaClItemList **ipp;
- struct NaClItemList *ip;
-
- if (!new_entry)
- return 0;
-
- new_entry->datum = obj;
-
- for (ipp = &self->head; 0 != (ip = *ipp); ipp = &ip->next) {
- if ((*self->cmp_functor->vtbl->OrderCmp)(self->cmp_functor,
- obj, ip->datum) >= 0) {
- break;
- }
- }
-
- new_entry->next = ip;
- *ipp = new_entry;
- return 1;
-}
-
-
-struct NaClContainerIter *NaClContainerListFind(
- struct NaClContainer *vself,
- void *key,
- struct NaClContainerIter *vout) {
- struct NaClContainerList *self = (struct NaClContainerList *) vself;
- struct NaClItemList **ipp;
- struct NaClItemList *ip;
- struct NaClContainerListIter *out = (struct NaClContainerListIter *) vout;
-
- for (ipp = &self->head; (ip = *ipp) != 0; ipp = &ip->next) {
- if ((*self->cmp_functor->vtbl->OrderCmp)(self->cmp_functor,
- key, ip->datum) == 0) {
- break;
- }
- }
- out->cur = ipp;
-
- vout->vtbl = &kNaClContainerListIterVtbl;
- return vout;
-}
-
-
-void NaClContainerListDtor(struct NaClContainer *vself) {
- struct NaClContainerList *self = (struct NaClContainerList *) vself;
- struct NaClItemList *cur, *next;
-
- for (cur = self->head; cur; cur = next) {
- next = cur->next;
- free(cur->datum);
- free(cur);
- }
-}
-
-
-int NaClContainerListIterCtor(struct NaClContainer *vself,
- struct NaClContainerIter *viter) {
- struct NaClContainerList *self = (struct NaClContainerList *) vself;
- struct NaClContainerListIter *iter = (struct NaClContainerListIter *) viter;
-
- iter->cur = &self->head;
-
- viter->vtbl = &kNaClContainerListIterVtbl;
- return 1;
-}
+#include "native_client/src/trusted/generic_container/container_hash_table.h"
+#include "native_client/src/include/portability.h"
static struct NaClContainerVtbl const kNaClContainerHashTblVtbl = {
NaClContainerHashTblInsert,
« no previous file with comments | « src/trusted/generic_container/container_hash_table.h ('k') | src/trusted/generic_container/container_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698