Exemplo n.º 1
0
void print(Node *head){
    // Traverse to print
    NodeStack *s = (NodeStack *)malloc(sizeof(NodeStack));
    Node *current;
    initStack(s);

    tryPush(s, head);
    while(isNotEmpty(s)){
        current = pop(s);
        tryPush(s, current->right);
        tryPush(s, current->left);

        if (current->word != ""){
            printf(">%s<", current->word);
        }
    }

    printf("\n");
    free(s);
}
Exemplo n.º 2
0
Node *findParentOfNode(Node *head, char *word){
    // Traverse to print
    NodeStack *s = (NodeStack *)malloc(sizeof(NodeStack));
    Node *current = NULL;
    initStack(s);

    tryPush(s, head);
    while(isNotEmpty(s)){
        current = pop(s);
        tryPush(s, current->right);
        tryPush(s, current->left);

        if ((current->right != NULL && current->right->word == word)
            || (current->left != NULL && current->left->word == word)){
            break;
        }
    }

    free(s);
    return current;
}
Exemplo n.º 3
0
	int tryPush(const T& data)
	{
		return tryPush(&data, sizeof(data));
	}
 void push(T const& item) {
     if( !tryPush(item) ) {
         throw Exception("Attempted push on full ReadWriteRingBuffer.");
     }
 }
Exemplo n.º 5
0
	int tryPush(const uint8_t priority, const T& data)
	{
		return tryPush(priority, &data, sizeof(data));
	}
Exemplo n.º 6
0
static void
client( Event ev, void *arg )
{
    Part_s	participants, *p;
    XObj	self = (XObj)arg;
    XObj	llp;
    PState	*ps = (PState *)self->state;
    int		testNumber = 0, len, count, lenindex, noResponseCount = 0;
    long        port = SERVERPORT;
    
    xAssert(xIsXObj(self));

    xTrace1(prottest, TR_ALWAYS, "sending to %s", ipHostStr(&ps->server));
    printf("DGRAM timing test\n");
    llp = xGetDown(self, 0);
    if ( ! xIsProtocol(llp) ) {
	xError("Test protocol has no lower protocol");
	return;
    }
    printf("I am the client\n");
    if ( ps->delay ) {
	xTrace1(prottest, TR_ALWAYS, "Delaying %d seconds", ps->delay);
	Delay( ps->delay * 1000 );
    }
    self->demux = clientDemux;

    p = &participants;
    partInit(p, 1);
    partPush(*p, &ps->server, sizeof(IPhost));
    partPush(*p, &port, sizeof(long));
    ps->lls = xOpen(self, self, llp, p, self->path);
    if ( ps->lls == ERR_XOBJ ) {
	printf("%s test: open failed!\n", PROT_STRING);
	xError("End of test");
	return;
    }
    /*
     * HACK! client will steal an event thread that it will not return
     * for a while.
     */
    if ( xkPolicyFixedFifo(&ps->dgramtest_priority, sizeof(ps->dgramtest_priority)) != XK_SUCCESS ) {
        printf("WARNING: xk_service_thread is being TIMESHARED!\n");
    }
    /* 
     * Delay to allow incoming messages to finalize opens (if necessary)
     */
    Delay(1000);
    for (lenindex = 0; lenindex < sizeof(lens)/sizeof(long) || ps->loop;
	 lenindex++) {
	if (lenindex >= sizeof(lens)/sizeof(long)) {
	    lenindex = 0;
	}
	len = lens[lenindex];
#ifdef VERBOSE
	printf("Sending (%d, [%c]) ...\n", ++testNumber, ps->mark);
#endif /* VERBOSE */
	count = tryPush(self, ps->lls, xk_trips, len);
	if ( count == xk_trips ) {
#ifdef VERBOSE
	    printf("\n[%c] len = %4d, %d trips: %6d.%06d\n", 
		   ps->mark, len, xk_trips, ps->nettime.sec, ps->nettime.usec);
#endif /* VERBOSE */
	}
	if ( count == 0 ) {
	    if ( noResponseCount++ == FAILURE_LIMIT ) {
		printf("Server looks dead.  I'm outta here.\n");
		break;
	    }
	} else {
	    noResponseCount = 0;
	}
	Delay(DELAY * 1000);
    }
    printf("[%c] End of test\n", ps->mark);
    xClose(ps->lls);
    ps->lls = 0;
    xTrace0(prottest, TR_FULL_TRACE, "test client returns");
 out:
    {
	/*
	 * restore the event priority!
	 */
	int         new_priority = XK_EVENT_THREAD_PRIORITY;

	if ( xkPolicyFixedFifo(&new_priority, sizeof(new_priority)) != XK_SUCCESS ) {
	    printf("WARNING: xk_service_thread is being lost!\n");
	}
    }
}