view src/insert_verification/include/akashaLLRBContext.h @ 38:593ab851ad76

Convert C function to cs (getMinHeight)
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Mon, 13 Jun 2016 11:47:37 +0900
parents be67b0312bea
children 81717f43ea00
line wrap: on
line source

/* Context definition for llrb example */
#include "stack.h"

#define ALLOCATE_SIZE 20000000
#define LIMIT_OF_VERIFICATION_SIZE 8

enum Code {
    ShowTree,
    IterateInsertion,
    PutAndGoToNextDepth,
    ShowTrace,
    VerifySpecification,
    DuplicateIterator,
    DuplicateIteratorElem,
    DuplicateTree,
    GoToPreviousDepth,

    /* definitions from llrb */
    Allocator,
    Put,
    Replace,
    Insert,
    Compare,
    RotateL,
    RotateR,
    SetTree,
    InsertCase1,
    InsertCase2,
    InsertCase3,
    InsertCase4,
    InsertCase4_1,
    InsertCase4_2,
    InsertCase5,
    StackClear,
    Get,
    Search,
    Delete,
    Delete1,
    Delete2,
    Delete3,
    Replace_d1,
    Replace_d2,
    FindMax1,
    FindMax2,
    DeleteCase1,
    DeleteCase2,
    DeleteCase3,
    DeleteCase4,
    DeleteCase5,
    DeleteCase6,
    Exit,
};

enum Relational {
    EQ,
    GT,
    LT,
};

enum UniqueData {
    Allocate,
    Tree,
    Node,
    Iter,
    AkashaInfo,
};

struct Context {
    enum Code next;
    enum Code prev;
    unsigned int codeNum;
    __code (**code) (struct Context*);
    void* heapStart;
    void* heap;
    unsigned long heapLimit;
    unsigned long dataNum;
    stack_ptr code_stack;
    stack_ptr node_stack;
    union Data **data;
};

union Data {
    struct Comparable { // inteface
        enum Code compare;
        union Data* data;
    } compare;
    struct Count {
        enum Code next;
        long i;
    } count;
    struct Tree {
        enum Code next;
        struct Node* root;
        struct Node* current;
        struct Node* deleted;
        int result;
    } tree;
    struct Node {
        // need to tree
        enum Code next;
        int key; // comparable data segment
        int value;
        struct Node* left;
        struct Node* right;
        // need to balancing
        enum Color {
            Red,
            Black,
        } color;
    } node;
    struct Allocate {
        enum Code next;
        long size;
    } allocate;

    /* for verification */
    struct IterElem {
        unsigned int val;
        struct IterElem* next;
    } iterElem;
    struct Iterator {
        struct Tree* tree;
        struct Iterator* previousDepth;
        struct IterElem* head;
        struct IterElem* last;
        unsigned int  iteratedValue;
        unsigned long iteratedPointDataNum;
        void*         iteratedPointHeap;
    } iterator;
    struct AkashaInfo {
        unsigned int minHeight;
        unsigned int maxHeight;
        struct AkashaNode* akashaNode;
    } akashaInfo;
    struct AkashaNode {
        unsigned int       height;
        struct Node*       node;
        struct AkashaNode* nextAkashaNode;
    } akashaNode;
};