view final_pre/src/initLLRBContext.c @ 7:28f900230c26

add final_pre
author ryokka
date Mon, 19 Feb 2018 23:32:24 +0900
parents
children
line wrap: on
line source

__code initLLRBContext(struct Context* context, int num) {
    context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
    context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
    context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
    context->heapStart = malloc(context->heapLimit);

    context->codeNum = Exit;

    context->code[Code1]      = code1_stub;
    context->code[Code2]      = code2_stub;
    context->code[Code3]      = code3_stub;
    context->code[Code4]      = code4;
    context->code[Code5]      = code5;
    context->code[Find]       = find;
    context->code[Not_find]   = not_find;
    context->code[Code6]      = code6;
    context->code[Put]        = put_stub;
    context->code[Replace]    = replaceNode_stub;
    context->code[Insert]     = insertNode_stub;
    context->code[RotateL]    = rotateLeft_stub;
    context->code[RotateR]    = rotateRight_stub;
    context->code[InsertCase1]   = insert1_stub;
    context->code[InsertCase2]   = insert2_stub;
    context->code[InsertCase3]   = insert3_stub;
    context->code[InsertCase4]   = insert4_stub;
    context->code[InsertCase4_1] = insert4_1_stub;
    context->code[InsertCase4_2] = insert4_2_stub;
    context->code[InsertCase5]   = insert5_stub;
    context->code[StackClear]    = stackClear_stub;
    context->code[Exit]       = exit_code;

    context->heap = context->heapStart;

    context->data[Allocate] = context->heap;
    context->heap += sizeof(struct Allocate);

    context->data[Tree] = context->heap;
    context->heap += sizeof(struct Tree);

    context->data[Node] = context->heap;
    context->heap += sizeof(struct Node);

    context->dataNum = Node;

    struct Tree* tree = &context->data[Tree]->tree;
    tree->root = 0;
    tree->current = 0;
    tree->deleted = 0;

    context->node_stack = stack_init(sizeof(struct Node*), 100);
    context->code_stack = stack_init(sizeof(enum Code), 100);
}