Exemplo n.º 1
0
void test_mapRemove_given_Ali_and_ali_is_in_the_list_of_3_element_in_the_map_and_should_remove_Ali_and_return_it_to_caller(){
  Person *Ali = personNew("Ali",25,70.3);
  Person *Zorro = personNew("Zorro",60,55.4);
  Person *Kikuri = personNew("Kikuri",48,46.4);
  Person *person;

  List *list = listNew(Ali, NULL);
  list = listAdd(Zorro,list);
  list = listAdd(Kikuri,list);
  
  Map *map = mapNew(5);
  map->bucket[3] = list;
  hash_ExpectAndReturn(Kikuri,3);
  
  // listDump(list, personDump);
  
  person = mapRemove(map , Kikuri ,comparePerson, hash);
  
  // listDump(list, personDump);
  
  TEST_ASSERT_NULL(person);
  TEST_ASSERT_NULL(getPersonFromBucket(map->bucket[3]));
  TEST_ASSERT_NOT_NULL(getPersonFromBucket(((List *)map->bucket[3])->next));
  TEST_ASSERT_NOT_NULL(getPersonFromBucket(((List *)map->bucket[3])->next->next));
  TEST_ASSERT_EQUAL_Person(Zorro,getPersonFromBucket(((List *)map->bucket[3])->next));
  TEST_ASSERT_EQUAL_Person(Ali,getPersonFromBucket(((List *)map->bucket[3])->next->next));
}
Exemplo n.º 2
0
/// BUGGS
int listAdd(pList list, int uid, tListData data)
{
    if(uid < list->uid && list->left == 0)
    {
        pList newItem = listCreate();
        newItem->uid = uid;
        newItem->data = data;
        list->left = newItem;
        list->level += 1;
        return 1;
    }
    if(uid > list->uid && list->right == 0)
    {
        pList newItem = listCreate();
        newItem->uid = uid;
        newItem->data = data;
        list->right = newItem;
        list->level += 1;
        return 1;
    }
    if(list->level!=0)
    {
        int result = 0;
        if(uid < list->uid)
            result = listAdd(list->left, uid, data);
        else if(uid > list->uid)
            result = listAdd(list->right, uid, data);
        else if(uid == list->uid)
            result = 0;
        listSkew(list);
        listSplit(list);
        return result;
    }
}
Exemplo n.º 3
0
/*
 * heap_ptr_t paralloc(size_t amt)
 *    @param amt : the amount of memory to allocate
 *    @returns on success : an offset (relative to the global `heaploc` defined
 *                          in `paralloc.h`)
 *    @return on error : -1 (and set errno to the appropriate value).
 *
 *    Allocates the requested amount of memory from the shared memory segment.
 */
heap_ptr_t paralloc(size_t amt) {
    if( amt <= 0) {
        //bad argument
        errno = EINVAL;
        return -1;
    }
    pid_t pid = getpid();
    int arena = pid % NUM_ARENAS;

    //BEGIN CRITICAL SECTION
    semaphore(wait_mutex[arena]);

    int offset = 0;
    linked_list* list = arenas[arena];
    list_node* current = list->head;
    list_node* prev = 0;

    //first-fit algorithm
    while( current) {
        int freesize = current->start - offset;
        if( freesize >= amt) {
            //we found a fit, need to make a node
            list_node* add = malloc( sizeof( list_node));
            add->start = offset;
            add->end = offset + amt;
            add->next = 0;

            //add node to list
            listAdd( list, add, prev);

            semaphore( signal_mutex[arena]);
            return offset;
        }
        offset = current->end;
        prev = current;
        current = current->next;
    }

    if( list->end - offset >= amt) {
        list_node* add = malloc( sizeof( list_node));
        add->start = offset;
        add->end = offset + amt;
        add->next = 0;
        listAdd( list, add, prev);

        semaphore( signal_mutex[arena]);
        return offset;
    }

    semaphore(signal_mutex[arena]);
    //END CRITICAL SECTION

    //out of memory error
    errno = ENOMEM;
    return -1;
}
Exemplo n.º 4
0
void test_listRemove_given_11_12_should_remove_11_and_remain_1_size(void)

{

 listAdd(list , 11);

 listAdd(list , 12);

 UnityAssertEqualNumber((_U_SINT)((11)), (_U_SINT)((listRemove(list))), (((void *)0)), (_U_UINT)61, UNITY_DISPLAY_STYLE_INT);

 UnityAssertEqualNumber((_U_SINT)((1)), (_U_SINT)((list->size)), (((void *)0)), (_U_UINT)62, UNITY_DISPLAY_STYLE_INT);

 ListDel(list);

}
Exemplo n.º 5
0
void
OFVALUE::set_nameValuei( const char *name, const char *new_value )
{
    char *buf = new char[OFOS::strlen(name) +
                         1 + 
                         OFOS::strlen(new_value) + 1];
    OFOS::strcpy(buf, name);
    OFOS::strcat(buf, "=");
    
    ofuint32 index = 0;
    for (ofint64 j = 1; !index && j <= listSize(); ++j)
    {
        OFVALUE temp = listRetrieve( j );
        if ( !OFOS::strnicmp( temp.get_string(), buf, OFOS::strlen( buf ) ) )
        {
            index = j;
            OFOS::strcat(buf, new_value);
            temp.set( buf );
            listReplace( &temp, j );
        }
    }

    if ( !index )
    {
        OFOS::strcat(buf, new_value); 
        OFVALUE temp;           
        temp.set( buf );
        listAdd( &temp );
    }

    delete [] buf;
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {

	//variables declaration
	FILE *file  = fopen(argv[1],"r");					//open file given by user
	char ch;
	char x[50];
	int i = 0;
	//create new list
	list *list;
	listCreate(&list);

	if(file!=NULL) {							//word only if file exists

		while(fscanf(file, "%s", x)!=EOF) {				//read string from file
			listAdd(x, list);						//call listAdd to add word
		}
		fclose(file);							//close file after operation
		list_sort(list);							//sort the list according to word count
		listPrint(list);							//print the list
		listDelete(list);							//free the list
		free(list);
	}
	
	return 0;								//bye!
}
Exemplo n.º 7
0
//將該點加入 header_table
struct header_table *add_header_table(struct header_table *htable, struct node *current_node, short value) {
	while(htable->no != value) {
		htable = htable->next;			
	}
	listAdd(htable->cond, current_node);
	return htable;
}
Exemplo n.º 8
0
wlTilesets wlTilesetsReadFile(char *filename)
{
    FILE *file;
    wlImages tiles;
    wlTilesets tilesets;

    // Validate parameters
    assert(filename != NULL);

    // Open the file for reading and abort if this fails
    file = fopen(filename, "rb");
    if (!file) return NULL;

    // Create the tilesets structure
    tilesets = malloc(sizeof(wlTilesetsStruct));
    listCreate(tilesets->tilesets, &(tilesets->quantity));

    // Read the tilesets
    while ((tiles = wlTilesReadStream(file)))
    {
        listAdd(tilesets->tilesets, tiles, &tilesets->quantity);
    }

    // Close the file stream
    fclose(file);

    // Return the tilesets
    return tilesets;
}
Exemplo n.º 9
0
SettingsDialog::SettingsDialog(QWidget* parent)
    : QDialog(parent)
{
    m_listChanged = false;
    m_list = new QStringList(KLanSettings::shortMsgList());

    m_autoStart = new QCheckBox("Start server on startup");
    m_autoStart->setChecked(KLanSettings::autoStart());
    m_useBroadcast = new QCheckBox("Use broadcasting to find other users");
    m_useBroadcast->setChecked(KLanSettings::useBroadcast());
    m_broadcastPort = new QLabel("Broadcast Port:");
    m_broadcastPortEdit = new QSpinBox();
    m_broadcastPortEdit->setMinimum(0);
    m_broadcastPortEdit->setMaximum(65535);
    m_broadcastPortEdit->setValue(KLanSettings::broadcastPort());
    m_broadcastPortEdit->setEnabled( m_useBroadcast->isEnabled() );
    m_listLb = new QLabel("Your Short Messages:");
    m_listModel = new QStringListModel(this);
    m_listView = new QListView();
    m_listView->setModel(m_listModel);
    m_listModel->setStringList(KLanSettings::shortMsgList());
    m_addBtn = new KPushButton(KIcon("list-add"), "Add");
    m_rmBtn = new KPushButton(KIcon("list-remove"), "Remove");

    m_acceptBtn = new KPushButton(KIcon("dialog-ok"), "Ok");
    m_acceptBtn->setDefault(true);
    m_rejectBtn = new KPushButton(KIcon("dialog-cancel"), "Cancel");

    m_broadcastLayout = new QHBoxLayout();
    m_broadcastLayout->addWidget(m_broadcastPort);
    m_broadcastLayout->addWidget(m_broadcastPortEdit);
    m_listBtnLayout = new QHBoxLayout();
    m_listBtnLayout->addWidget(m_addBtn);
    m_listBtnLayout->addWidget(m_rmBtn);
    m_buttonLayout = new QHBoxLayout();
    m_buttonLayout->addStretch();
    m_buttonLayout->addWidget(m_acceptBtn);
    m_buttonLayout->addWidget(m_rejectBtn);
    m_vSettingsLayout = new QVBoxLayout();
    m_vSettingsLayout->addWidget(m_autoStart);
    m_vSettingsLayout->addWidget(m_useBroadcast);
    m_vSettingsLayout->addLayout(m_broadcastLayout);
    m_vSettingsLayout->addWidget(m_listLb);
    m_vSettingsLayout->addWidget(m_listView);
    m_vSettingsLayout->addLayout(m_listBtnLayout);
    m_hSettingsLayout = new QHBoxLayout();
    m_hSettingsLayout->addLayout(m_vSettingsLayout);
    m_hSettingsLayout->addStretch();
    m_mainLayout = new QVBoxLayout();
    m_mainLayout->addLayout(m_hSettingsLayout);
    m_mainLayout->addStretch();
    m_mainLayout->addLayout(m_buttonLayout);
    setLayout(m_mainLayout);

    connect( m_useBroadcast, SIGNAL(toggled(bool)), m_broadcastPortEdit, SLOT(setEnabled(bool)) );
    connect( m_addBtn, SIGNAL(clicked()), this, SLOT(listAdd()) );
    connect( m_rmBtn, SIGNAL(clicked()), this, SLOT(listRm()) );
    connect( m_acceptBtn, SIGNAL(clicked()), this, SLOT(accept()) );
    connect( m_rejectBtn, SIGNAL(clicked()), this, SLOT(reject()) );
}
Exemplo n.º 10
0
SList* listConcatUnique(SList* list1, SList* list2, int(*cmp)(void*, void*))
{
	if(!list1 || listEmpty(list1))
	{
		list1->head = list2->head;
		list1->curr = list2->curr;
	}
	else if(!list2 || listEmpty(list2))
	{
		return list1;
	}
	else
	{
		listHead(list2);
		do
		{
			int found = 0;
			listHead(list1);
			do
			{
				found = cmp(listCurrent(list1), listCurrent(list2));
			}while(!found && listNext(list1));

			if(!found)
			{
				listAdd(list1, listCurrent(list2));
			}
		}while(listNext(list2));
	}
	return list1;
}
Exemplo n.º 11
0
FFont * newFFont(char * loc)
{
	//Creates a new font
	
	FFont * temp = (FFont *) c_malloc(sizeof(FFont));

	int w, h, size, x, y;
	short bpp = 0;
	char * data;
	Tex * letter;
	temp->nLetters = 0;

	data = loadTGA(loc, &w, &h, &bpp);
	size = w / 16;
	/* Loading the data from our font image						(deylen - 14/05/2009)*/

	for (y=0; y < 16; y++)
		for (x=0; x < 16; x++){
			letter = newLetter(data, x, 15 - y, size, bpp, w);
			temp->letters = (Tex **) listAdd((void **) temp->letters, size_tex_p, letter, &temp->nLetters);
		}
	/* Running through the image and creating each letter					(deylen - 14/05/2009)*/

	temp->size = size / 16.0;
	free(data);

	return temp;
}
Exemplo n.º 12
0
static int ifiDbCallbackBuildList(void *pCallbackCtx, list_t *pRow)
{	int again = 1;

	if(pRow != NULL)
	{	ifiDbCtx_t *pCtx = (ifiDbCtx_t *)pCallbackCtx;
		idrc_t idrc;

		memset(&idrc, 0, sizeof(idrc));
		// iterate the cols
		listForEach(pRow, &ifiDbCallbackBuildListCol, &idrc);

		// we need at least the first two columns
		if(idrc.colIndex >= 2)
		{	ir_t *pIr = NULL;
#ifdef _UNIT_TEST_IFIDB
			ifiDb_ShowRow(&idrc);
#endif
			pIr = ifiDb_IrBuild(pCtx->pSessionId, idrc.pCols);
			if(pIr != NULL)
				listAdd(pCtx->pIfiDb, pIr);
		}
	}

	return again;
}
Exemplo n.º 13
0
static int32_t protocalPushEvent(ProtocalStatusType *pProtocal)
{
    int32_t ret;
    EventStackType *pEvent;
    int copyLen;

    ret = protocalAllocEmptyEventMemory(pProtocal, &pEvent);
    if (ret)
    {
//        Trace("error, no memory!");
        return ret;
    }
    pEvent->cmd = pProtocal->cmd;
    pEvent->cmdType |= pProtocal->cmdType;
    pEvent->buffSize = pProtocal->bufferIndex;
    copyLen = pProtocal->bufferIndex < PROTOCAL_MAX_DATA_LENGTH ?
              pProtocal->bufferIndex : PROTOCAL_MAX_DATA_LENGTH;
    memcpy(pEvent->buff, pProtocal->buffer, copyLen);
    ret = listAdd(&pProtocal->eventStack, (uint32_t)pEvent);
    if (pProtocal->pfnSchedule)
    {
        pProtocal->pfnSchedule();
    }

}
Exemplo n.º 14
0
static list_t* ifiDb_IrBuildAddressList(char *pStr, int *pAfType)
{	list_t *pList = NULL;

	if(pStr != NULL && *pStr)
	{	char *p1;
		char *p2;

		pList = listCreate();
		while((p1 = mlfi_stradvtok(&pStr, ',')) != NULL && *p1)
		{
			p2 = p1;
			p1 = mlfi_stradvtok(&p2, '/');

			if(p1 != NULL && p2 != NULL && *p1 && p2)
			{	ira_t ira;

				ira.maskLen = atoi(p2);
				if((*pAfType == AF_UNSPEC || *pAfType == AF_INET)
					&& ira.maskLen <=32
					&& inet_pton(AF_INET, p1, &ira.ipv4)
					)
				{
					*pAfType = ira.afType = AF_INET;
				}
				else if(
					(*pAfType == AF_UNSPEC || *pAfType == AF_INET6)
					&& ira.maskLen <= 128
					&& inet_pton(AF_INET6, p1, &ira.ipv6)
					)
				{
					*pAfType = ira.afType = AF_INET6;
				}
				else
				{
					*pAfType = ira.afType = AF_UNSPEC;
					ira.maskLen = 0;
				}

				if(ira.afType != AF_UNSPEC)
				{	ira_t *pIra = calloc(1, sizeof(ira_t));

					if(pIra != NULL)
					{
						*pIra = ira;
						listAdd(pList, pIra);
					}
				}
			}
		}

		if(listQty(pList) == 0)
		{
			listDestroy(pList, NULL, NULL);
			pList = NULL;
		}
	}

	return pList;
}
Exemplo n.º 15
0
void test_listAdd_given_4_2_should_add_4_2(void)

{

 listAdd(list , 4);

 listAdd(list , 2);

 UnityAssertEqualNumber((_U_SINT)((4)), (_U_SINT)((list->buffer[0])), (((void *)0)), (_U_UINT)29, UNITY_DISPLAY_STYLE_INT);

 UnityAssertEqualNumber((_U_SINT)((2)), (_U_SINT)((list->buffer[1])), (((void *)0)), (_U_UINT)30, UNITY_DISPLAY_STYLE_INT);



 ListDel(list);

}
Exemplo n.º 16
0
Route* _routeNew(void* firstStation)
{
    Route* result = (Route*)calloc(1, sizeof(Route));
    result->links = listNew();
    result->stations = listNew();
    listAdd(result->stations, firstStation);
    return result;
}
Exemplo n.º 17
0
int32_t jniSendData(void *pData, uint32_t len)
{
    sendDataTypes *pBuffer = (sendDataTypes*)malloc(sizeof(sendDataTypes));

    memcpy(pBuffer->sendBytes, pData, len);
    pBuffer->len = len;
    listAdd(&sendBuffer, (uint32_t)pBuffer);
}
Exemplo n.º 18
0
void processICMP(struct icmp *icmp_header, struct ip *ip_header) {
    if (icmp_header->icmp_code != 0) {
        printf("BAD ICMP CODE\n\n\n");
        return;
    }

    if (icmp_header->icmp_type == ICMP_ECHO) {

        struct icmp_state state;
        state.idNumber = icmp_header->icmp_hun.ih_idseq.icd_id;
        state.ip_src = ip_header->ip_src;

        if (containsNode(icmpStateList, &state, icmp_stateInList) == 0) {

            printf("New State ");
            struct icmp_state * newState;
            newState = (struct icmp_state *) malloc(sizeof(struct icmp_state));
            newState->idNumber = state.idNumber;
            newState->ip_src.s_addr = state.ip_src.s_addr;
            listAdd(icmpStateList, newState);

        }
        printf("Ping received from %s ", inet_ntoa(ip_header->ip_src));
        printf("to %s ID:%d icm_state_size %d\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);

        ip_header->ip_src.s_addr = inet_addr(listenIP);
        ip_header->ip_dst.s_addr = inet_addr(serverIP);

        sendIp(ip_header);

    } else if (icmp_header->icmp_type == ICMP_ECHOREPLY) {

        printf("ECHOREPLY received from %s ", inet_ntoa(ip_header->ip_src));
        printf("to %s ID:%d icm_state_size %d\n\n\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);

        struct icmp_state state;
        state.idNumber = icmp_header->icmp_hun.ih_idseq.icd_id;
        state.ip_src = ip_header->ip_src;
        struct icmp_state * savedState;
        struct node* fetchedNode;
        if ((fetchedNode = fetchNode(icmpStateList, &state, icmp_stateInList))
                == NULL) {
            printf("BAD ICMP REPLY ID\n\n\n");
            return;
        }
        savedState = fetchedNode->data;
        ip_header->ip_src.s_addr = inet_addr(listenIP);
        ip_header->ip_dst.s_addr = savedState->ip_src.s_addr;

        sendIp(ip_header);

    } else {
        printf("ICMP BAD TYPE received from %s ", inet_ntoa(ip_header->ip_src));
        printf("to %s ID:%d icm_state_size %d\n\n\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);
    }
}
Exemplo n.º 19
0
int gsl_new_font (char * loc) 
{
	//To be called from lisp

	FFont * temp = newFFont(loc);

	fontList = (FFont **) listAdd((void **) fontList, size_ffont_p, temp, &nFonts);

	return nFonts-1;	/* -1 because listAdd automatically increments the list 			(deylen - 14/05/2009)*/
}
Exemplo n.º 20
0
uint64_t algorithm() {
    uint64_t primeSum=2;
    cellList list;

    listInit(&list);
    listAdd(cellNew(2),&list);

    //printf("%"PRIu32" %"PRIu32"\n",list.first->value,list.last->value);

    for(uint64_t i=3; i<LIMIT; i++)
        if(isPrime(i,&list) == TRUE) {
            printf("-->%"PRIu64"\n",i);
            listAdd(cellNew(i),&list);
            primeSum+=i;
        }

    listDestroy(&list);
    return primeSum;
}
Exemplo n.º 21
0
void test_listIsFull_given_6_7_8_9_10_should_throw_exception(void)

{

 unsigned int err;



 { jmp_buf *PrevFrame, NewFrame; unsigned int MY_ID = (0); PrevFrame = CExceptionFrames[(0)].pFrame; CExceptionFrames[MY_ID].pFrame = (jmp_buf*)(&NewFrame); CExceptionFrames[MY_ID].Exception = (0x5A5A5A5A); if (_setjmp(NewFrame) == 0) { if (&PrevFrame)

 {

  listAdd(list , 6);

  listAdd(list , 7);

  listAdd(list , 8);

  listAdd(list , 9);

  listAdd(list , 10);

  UnityFail( ("Should throw ERROR_LIST_FULL exception"), (_U_UINT)46);;

 }

 else { } CExceptionFrames[MY_ID].Exception = (0x5A5A5A5A); } else { err = CExceptionFrames[MY_ID].Exception; err=err; } CExceptionFrames[MY_ID].pFrame = PrevFrame; } if (CExceptionFrames[(0)].Exception != (0x5A5A5A5A))

 {

  UnityAssertEqualNumber((_U_SINT)((ERROR_LIST_FULL)), (_U_SINT)((err)), ("Expect ERROR_LIST_FULL exception"), (_U_UINT)50, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((5)), (_U_SINT)((list->size)), (((void *)0)), (_U_UINT)51, UNITY_DISPLAY_STYLE_INT);

 }





}
Exemplo n.º 22
0
void test_listRemove_given_13_14_should_Remove_13_14_and_throw_exception(void)

{

 unsigned int err;



 { jmp_buf *PrevFrame, NewFrame; unsigned int MY_ID = (0); PrevFrame = CExceptionFrames[(0)].pFrame; CExceptionFrames[MY_ID].pFrame = (jmp_buf*)(&NewFrame); CExceptionFrames[MY_ID].Exception = (0x5A5A5A5A); if (_setjmp(NewFrame) == 0) { if (&PrevFrame)

 {

  listAdd(list , 13);

  listAdd(list , 14);



  UnityAssertEqualNumber((_U_SINT)((13)), (_U_SINT)((listRemove(list))), (((void *)0)), (_U_UINT)75, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((14)), (_U_SINT)((listRemove(list))), (((void *)0)), (_U_UINT)76, UNITY_DISPLAY_STYLE_INT);

  UnityFail( ("Should throw ERROR_LIST_EMPTY exception"), (_U_UINT)77);;

 }

 else { } CExceptionFrames[MY_ID].Exception = (0x5A5A5A5A); } else { err = CExceptionFrames[MY_ID].Exception; err=err; } CExceptionFrames[MY_ID].pFrame = PrevFrame; } if (CExceptionFrames[(0)].Exception != (0x5A5A5A5A))

 {

  UnityAssertEqualNumber((_U_SINT)((ERROR_LIST_EMPTY)), (_U_SINT)((err)), ("Expect ERROR_LIST_EMPTY exception"), (_U_UINT)81, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((0)), (_U_SINT)((list->size)), (((void *)0)), (_U_UINT)82, UNITY_DISPLAY_STYLE_INT);

 }



 ListDel(list);

}
Exemplo n.º 23
0
END_TEST

START_TEST(test_strJoin)
{
    char **list;
    size_t size;

    listCreate(list, &size);
    listAdd(list, "foo", &size);
    listAdd(list, "bar", &size);
    listAdd(list, "xyz", &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo bar xyz"), NULL);
    fail_unless(strEquals(strJoin("()", list, size), "foo()bar()xyz"), NULL);
    listRemove(list, 1, &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo xyz"), NULL);
    listRemove(list, 1, &size);
    fail_unless(strEquals(strJoin(" ", list, size), "foo"), NULL);
    listRemove(list, 0, &size);
    fail_unless(strEquals(strJoin(" ", list, size), ""), NULL);
    listFree(list);
}
Exemplo n.º 24
0
Arquivo: battle.c Projeto: phoboz/yz
void init_battle_player(
    BATTLE *battle,
    PLAYER *player
)
{
    BATTLE_ACTOR *ba;

    ba = create_battle_actor(battle, player);
    listAdd(&battle->battleList, &ba->listNode);
    set_curr_battle_actor(battle, ba);
    set_curr_battle_state(battle, BATTLE_STATE_WAIT, NULL);
}
Exemplo n.º 25
0
//將兩結點串連
struct node * link_node(struct node *current_node, short value) {
	struct node *new_node = malloc(sizeof(struct node));	
	
	new_node->no 	  = value;
	new_node->parent  = current_node;
	new_node->counter = 1;
	new_node->child	  = NULL;
	
	listAdd(current_node->child, new_node);
	current_node = new_node;
	return current_node;
}
Exemplo n.º 26
0
int gsl_new_shader(char * vert, char * frag)
{
	Shader * temp = (Shader *) c_malloc(size_shader);
	temp->prog = temp->vert = temp->frag = 0;

	addShadersToProgram(temp, vert, frag);
	addShadersToProgram(temp, "", "b_w.frag2");

	temp->n = nShaders;
	shaderList = (Shader **) listAdd((void **) shaderList, size_shader_p, temp, &nShaders);

	return temp->n;
}
Exemplo n.º 27
0
void store(List *list , int value[] , int length)
{
	int i=0;
	
	for(i ; i<length ; i++)
	{
	
		if(!listIsFull(list))
		{
			listAdd(list, value[i]);
		}
	}
}
Exemplo n.º 28
0
Arquivo: battle.c Projeto: phoboz/yz
static int init_battle_steps(
    BATTLE *battle,
    BATTLE_ACTOR *ba
)
{
    int i, j, r, count;
    STEP_POINT *p;

    p = new_battle_step(ba->i, ba->j);
    listAdd(&ba->walkList, &p->listNode);

    r = ba->player->h->status.range;

    for (j = -r; j <= r; j++) {

        for (i = -r; i <= r; i++) {

            if (gettile_type_map(battle->world->map,
                                 (ba->i + i) * BMARKER_WIDTH,
                                 (ba->j + j) * BMARKER_HEIGHT))
                continue;

            if (get_battle_actor_at(battle, ba, ba->i + i, ba->j + j, 0) != NULL)
                continue;

            p = new_battle_step(ba->i + i, ba->j + j);
            listAdd(&ba->stepList, &p->listNode);
            count++;

        }

    }

    ba->cursor.i = ba->i;
    ba->cursor.j = ba->j;

    return count;
}
Exemplo n.º 29
0
int evaluateLiberties(char *board, int x, int y, struct linked_list *waiting, struct linked_list *evaled, struct linked_list *nolibs, char col, int turn){
	BOOLEAN first = (waiting == NULL);
	if ((x > width) || (y > length) || (x <= 0) || (y <= 0)) {
		return UNDECIDED;
	} else if (board[toIndex(x,y)] == SPACE) {
		return TRUE;
	} else if (board[toIndex(x,y)] != col) {
		return FALSE;
	} else if (listMember(waiting, x, y) == TRUE) {
		return UNDECIDED;
	} else if (listMember(evaled, x, y) == TRUE) {
		return TRUE;
	} else if (listMember(nolibs, x, y) == TRUE) {
		return FALSE;
	} else {
		waiting = listAdd(waiting, x, y);
		if (evaluateLiberties(board, x+1, y, waiting, evaled, nolibs, col, turn) == TRUE
		    || evaluateLiberties(board, x, y+1, waiting, evaled, nolibs, col, turn) == TRUE
		    || evaluateLiberties(board, x, y-1, waiting, evaled, nolibs, col, turn) == TRUE
		    || evaluateLiberties(board, x-1, y, waiting, evaled, nolibs, col, turn) == TRUE) {
			listAdd(evaled, x, y);
			waiting = listRemove(waiting, x, y);
			return TRUE;
		} else {
			if (first == TRUE) {
				while ((*waiting).next != NULL) {
					listAdd(nolibs, (*(*waiting).next).x, (*(*waiting).next).y);
					(*waiting).next = listRemove((*waiting).next, (*(*waiting).next).x, (*(*waiting).next).y);
				}
				listAdd(nolibs, (*waiting).x, (*waiting).y);
				SafeFree(waiting);
				return FALSE;
			} else {
				return UNDECIDED;
			}
		}
	}
}
Exemplo n.º 30
0
 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
     ListNode* result = new ListNode(0); //void node
     ListNode* tmp = result;
     int carry = 0;
     
     while(l1 || l2) {
         listAdd(tmp, l1, l2, carry);
     }
     if(carry) {
         tmp->next = new ListNode(carry);
     }
     
     return result->next;
 }