int main(int argc, char *argv[]) { SensorInfo *head = addSensor("Solar Panel", "V"); SensorInfo *node1 = addSensor("Test", "N/A"); SensorInfo *node2 = addSensor("Time",":"); SensorInfo *node3 = addSensor("Date", "\\"); addNodeToList(head, node1); addNodeToList(head, node2); addNodeToList(head, node3); printlist(head); printf("Size of SensorInfo: %lu bytes.\n\n", sizeof(*head)); SensorInfo *find = searchList("Date", head); printf("Node Found: %s\n", find->_sensorName); return 0; }
Node* NodeList::addOrUpdateNode(sockaddr* publicSocket, sockaddr* localSocket, char nodeType, uint16_t nodeId) { NodeList::iterator node = end(); if (publicSocket) { for (node = begin(); node != end(); node++) { if (node->matches(publicSocket, localSocket, nodeType)) { // we already have this node, stop checking break; } } } if (node == end()) { // if we already had this node AND it's a solo type then bust out of here if (soloNodeOfType(nodeType)) { return NULL; } // we didn't have this node, so add them Node* newNode = new Node(publicSocket, localSocket, nodeType, nodeId); if (socketMatch(publicSocket, localSocket)) { // likely debugging scenario with two nodes on local network // set the node active right away newNode->activatePublicSocket(); } if (newNode->getType() == NODE_TYPE_VOXEL_SERVER || newNode->getType() == NODE_TYPE_AVATAR_MIXER || newNode->getType() == NODE_TYPE_AUDIO_MIXER) { // this is currently the cheat we use to talk directly to our test servers on EC2 // to be removed when we have a proper identification strategy newNode->activatePublicSocket(); } addNodeToList(newNode); return newNode; } else { if (node->getType() == NODE_TYPE_AUDIO_MIXER || node->getType() == NODE_TYPE_VOXEL_SERVER) { // until the Audio class also uses our nodeList, we need to update // the lastRecvTimeUsecs for the audio mixer so it doesn't get killed and re-added continously node->setLastHeardMicrostamp(usecTimestampNow()); } // we had this node already, do nothing for now return &*node; } }
ListNode* partition(ListNode* head, int x) { ListNode *smallerHead = NULL; ListNode *smallerTail = NULL; ListNode *otherHead = NULL; ListNode *otherTail = NULL; while(head != NULL) { ListNode *temp = head->next; if(head->val < x) addNodeToList(head, smallerHead, smallerTail); else addNodeToList(head, otherHead, otherTail); head = temp; } if(smallerHead == NULL) return otherHead; smallerTail->next = otherHead; return smallerHead; }
void CodeMemoryReportFormatter::report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, int line) { SimpleString variableName = createVariableNameFromFileLineInfo(file, line); result->print(StringFromFormat("\t%s\n", getAllocationString(allocator, variableName, size).asCharString()).asCharString()); addNodeToList(variableName.asCharString(), memory, codeReportingList_); }
void adaugaJucatorLaEchipa(Team *echipa, Player *jucator, int laSfarsit) { if (echipa->firstPlayer == NULL) { echipa->firstPlayer = (Player*)malloc(sizeof(Player)); } addNodeToList(echipa->firstPlayer, jucator, laSfarsit); }