view src/parallel_execution/stack.c @ 144:d529c024e5a5

name fixes
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 10 Nov 2016 07:33:10 +0900
parents 4f6a660c14a1
children cc071cf1ba85
line wrap: on
line source

#include "context.h"
#include "stack.h"
#include "origin_cs.h"
#include <stdio.h>

union Data* createSingleLinkedStack(struct Context* context) {
    struct Stack* stack = &ALLOCATE(context, Stack)->stack;
    struct SingleLinkedStack* singleLinkedStack = &ALLOCATE(context, SingleLinkedStack)->singleLinkedStack;
    stack->stack = (union Data*)singleLinkedStack;
    singleLinkedStack->top = NULL;
    stack->push = C_pushSingleLinkedStack;
    stack->pop  = C_popSingleLinkedStack;
    stack->pop2  = C_pop2SingleLinkedStack;
    stack->get  = C_getSingleLinkedStack;
    stack->get2  = C_get2SingleLinkedStack;
    stack->isEmpty = C_isEmptySingleLinkedStack;
    return (union Data*)(stack);
}

void printStack1(union Data* data) {
    struct Node* node = &data->element.data->node;
    if (node == NULL) {
        printf("NULL");
    } else {
        printf("key = %d ,", node->key);
        printStack1((union Data*)data->element.next);
    }
}

void printStack(union Data* data) {
    printStack1(data);
    printf("\n");
}

__code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) {
    element->next = stack->top;
    element->data = data;
    stack->top = element;
    goto meta(context, next);
}

__code pushSingleLinkedStack_stub(struct Context* context) {
    struct Element* element = &ALLOCATE(context, Element)->element;
    goto pushSingleLinkedStack(context,
                               (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
                               element,
                               context->data[Stack]->stack.data,
                               context->data[Stack]->stack.next);
}

__code popSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) {
    if (stack->top) {
        *data = stack->top->data;
        stack->top = stack->top->next;
    } else {
        *data = NULL;
    }
    goto meta(context, next);
}

__code popSingleLinkedStack_stub(struct Context* context) {
    goto popSingleLinkedStack(context,
                               (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
                               &context->data[Stack]->stack.data,
                               context->data[Stack]->stack.next);
}

__code pop2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) {
    if (stack->top) {
        *data = stack->top->data;
        stack->top = stack->top->next;
    } else {
        *data = NULL;
    }
    if (stack->top) {
        *data1 = stack->top->data;
        stack->top = stack->top->next;
    } else {
        *data1 = NULL;
    }
    goto meta(context, next);
}

__code pop2SingleLinkedStack_stub(struct Context* context) {
    goto pop2SingleLinkedStack(context,
                               (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
                               &context->data[Stack]->stack.data,
                               &context->data[Stack]->stack.data1,
                               context->data[Stack]->stack.next);
}

__code getSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) {
    if (stack->top)
        *data = stack->top->data;
    else
        *data = NULL;
    goto meta(context, next);
}

__code getSingleLinkedStack_stub(struct Context* context) {
    goto getSingleLinkedStack(context,
                               (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
                               &context->data[Stack]->stack.data,
                               context->data[Stack]->stack.next);
}

__code get2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) {
    if (stack->top) {
        *data = stack->top->data;
        if (stack->top->next) {
            *data1 = stack->top->next->data;
        } else {
            *data1 = NULL;
        }
    } else {
        *data = NULL;
        *data1 = NULL;
    }
    goto meta(context, next);
}

__code get2SingleLinkedStack_stub(struct Context* context) {
    goto get2SingleLinkedStack(context,
                               (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
                               &context->data[Stack]->stack.data,
                               &context->data[Stack]->stack.data1,
                               context->data[Stack]->stack.next);
}

__code isEmptySingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, enum Code next,enum Code whenEmpty) {
    if (stack->top)
        goto meta(context, next);
    else
        goto meta(context, whenEmpty);
}

__code isEmptySingleLinkedStack_stub(struct Context* context) {
    goto isEmptySingleLinkedStack(context,
                               (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
                               context->data[Stack]->stack.next,
                               context->data[Stack]->stack.whenEmpty);
}