Mercurial > hg > GearsTemplate
view src/llrb/llrb.c @ 19:9302b1a48008
add llrb
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 21 Apr 2015 22:36:23 +0900 |
parents | |
children | 324c44f2076f |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include "llrbContext.h" #include "allocate.h" #include "origin_cs.h" #ifdef CLANG #define _CbC_retrun __return #define _CbC_environment __environment #endif #define NUM 100 #define ALLOCATE_SIZE 1024 extern __code initLLRBContext(struct Context* context); /* __code code1(Allocate allocate) { allocate.size = sizeof(long); allocate.next = Code2; goto Allocate(allocate); } */ __code code1(struct Context* context) { context->data[0]->allocate.size = sizeof(struct Node); context->data[0]->allocate.next = Put; context->data[0]->allocate.after_put = Code2; goto meta(context, Allocate); } __code meta(struct Context* context, enum Code next) { goto (context->code[next])(context); } __code put(struct Context* context) { context->data[context->dataSize]->node.key = context->data[0]->allocate.key; context->data[context->dataSize]->node.value = context->data[0]->allocate.value; if (context->root == 0) { context->root = context->data[context->dataSize]; context->root->node.color = Red; goto meta(context, context->data[0]->allocate.after_put); } goto meta(context, Insert); } __code insert(struct Context* context) { goto meta(context, context->data[0]->allocate.after_put); } /* __code code2(Allocate allocate, Count count) { count.count = 0; goto code3(count); } */ __code code2(struct Context* context) { goto meta(context, Exit); } int main() { struct Context* context = (struct Context*)malloc(sizeof(struct Context)); context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); context->data = malloc(sizeof(union Data**)*ALLOCATE_SIZE); context->heap = malloc(sizeof(union Data*)*ALLOCATE_SIZE); initLLRBContext(context); goto start_code(context, Code1); }