changeset 12:78dce131e9d6

Use allocator
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Fri, 18 Mar 2016 10:57:40 +0900
parents b13d2c8d4b47
children f0a1f02e8493
files src/insert_verification/akashaLLRBContext.c
diffstat 1 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/insert_verification/akashaLLRBContext.c	Wed Mar 16 17:19:50 2016 +0900
+++ b/src/insert_verification/akashaLLRBContext.c	Fri Mar 18 10:57:40 2016 +0900
@@ -42,8 +42,13 @@
 extern __code deleteCase6_stub(struct Context*);
 extern __code exitCode(struct Context*);
 
-__code initIterator(struct Context*);
+/* for allocator */
+extern void allocator(struct Context* context);
+
+
+__code initIterator(struct Context* context, struct Allocate* allocate, struct Iterator* iter);
 __code initFinishIterator(struct Context*, struct IterElem*);
+__code initIteratorElem(struct Context* context, struct Allocate* allocate, struct IterElem* prev);
 
 __code initLLRBContext(struct Context* context, enum Code next) {
     context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
@@ -98,28 +103,39 @@
     context->code_stack = stack_init(sizeof(enum Code), 100);
 
     context->next = next;
-    goto initIterator(context);
+    goto initIterator_stub(context);
 }
 
-__code initIterator(struct Context* context) {
-    struct IterElem* ie   = (struct IterElem*)malloc(sizeof(struct IterElem));
-    struct Iterator* iter = &context->data[Iter]->iterator;
+__code initIterator_stub(struct Context* context) {
+    goto initIterator(context, &context->data[Allocate]->allocate, &context->data[Iter]->iterator);
+}
+
+__code initIterator(struct Context* context, struct Allocate* allocate, struct Iterator* iter) {
+    struct IterElem* ie   = context->heap;
+    allocate->size = sizeof(struct IterElem);
+    allocator(context);
 
     ie->val    = 0;
     ie->next   = NULL;
     iter->tree = NULL;
     iter->head = ie;
 
-    goto initIteratorElem(context, ie);
+    goto initIteratorElem_stub(context, ie);
+}
+__code initIteratorElem_stub(struct Context* context, struct IterElem* prev) {
+    goto initIteratorElem(context, &context->data[Allocate]->allocate, prev);
 }
 
-__code initIteratorElem(struct Context* context, struct IterElem* prev) {
+__code initIteratorElem(struct Context* context, struct Allocate* allocate, struct IterElem* prev) {
     if (prev->val >= LIMIT_OF_VERIFICATION_SIZE) { goto initFinishIterator(context, prev); }
 
-    struct IterElem* ie = (struct IterElem *)malloc(sizeof(struct IterElem));
+    struct IterElem* ie = context->heap;
+    allocate->size = sizeof(struct IterElem);
+    allocator(context);
+
     ie->val             = prev->val + 1;
     prev->next          = ie;
-    goto initIteratorElem(context, ie);
+    goto initIteratorElem_stub(context, ie);
 }
 
 __code initFinishIterator(struct Context* context, struct IterElem* elem) {