int CS34DblList::GetTotalEntries() { int iRet = 0; if (MoveToHead()) { while (MoveNext()) { iRet++; } iRet++; } MoveToHead(); return iRet; }
//---------------------------------------------------------- //---------------------------------------------------------- const void* drmaa2_list_get(const drmaa2_list list, long pos) { _drmaa2_Node *node=NULL; if(list->current == NULL) { _drmaa2_err_set (DRMAA2_INTERNAL, "Current element of list is NULL!"); return NULL; } if(pos<0 || pos>=list->listsize) { _drmaa2_err_set (DRMAA2_INTERNAL, "Index of list is out of range!"); return NULL; } if(MoveToHead(list) != DRMAA2_SUCCESS) { _drmaa2_err_set (DRMAA2_INTERNAL, "Moving to head of list failed!"); return NULL; } do { if(list->current_pos==pos) { node=list->current; return node->value; } }while(MoveToNext(list) == DRMAA2_SUCCESS); return NULL; }
//---------------------------------------------------------- //---------------------------------------------------------- drmaa2_error drmaa2_list_del(drmaa2_list list, long pos) { void *oldData; _drmaa2_Node *oldNode; if(pos<0 || pos>=list->listsize) { return _drmaa2_err_set (DRMAA2_INTERNAL, "Index of list is out of range!"); } if(MoveToHead(list) != DRMAA2_SUCCESS) { return _drmaa2_err_set (DRMAA2_INTERNAL, "Moving to head of list failed!"); } do { if(list->current_pos==pos) break; }while(MoveToNext(list) == DRMAA2_SUCCESS); if(list->current == NULL) { return _drmaa2_err_set (DRMAA2_INTERNAL, "Current element of list is NULL!"); } oldData = list->current->value; oldNode = list->current; if(list->current == list->head) { if(list->current->next != NULL) list->current->next->prev = NULL; list->head = list->current->next; list->current = list->head; } else if(list->current == list->tail) { list->current->prev->next = NULL; list->tail = list->current->prev; list->current = list->tail; list->current_pos--; } else { list->current->prev->next = list->current->next; list->current->next->prev = list->current->prev; list->current = list->current->next; } free(oldData); free(oldNode); list->listsize--; return DRMAA2_SUCCESS; }
void set(int key, int value) { if (m_map.find(key) == m_map.end()){ //frame does not appear in the hash map, then //create a new entry and move to head //if the cache is full, erase from end of cache CacheEntry entry(key, value); if (m_LRU_cache.size() >= m_capacity) { m_map.erase(m_LRU_cache.back().key); m_LRU_cache.pop_back(); } m_LRU_cache.push_front(entry); m_map[key] = m_LRU_cache.begin(); return ; } m_map[key]->value = value; MoveToHead(key); }
//---------------------------------------------------------- //---------------------------------------------------------- void display_list(drmaa2_list list) { if(list->current == NULL) return; if(MoveToHead(list) != DRMAA2_SUCCESS) { printf("List is empty!\n"); return; } do { printf("%s\n",(char*)(list->current->value)); } while(MoveToNext(list) == DRMAA2_SUCCESS); }
int get(int key) { if (m_map.find(key) == m_map.end()) return -1; MoveToHead(key); return m_map[key]->value; }