void (list_del) (SCL_list_t a_list) { S_node_t* node1 = a_list->head; S_node_t* node2 = a_list->head; while (node1 != NULL) { node2 = node1->succ; SCL_DEALLOCATOR ((void*)node1); node1 = node2; } SCL_DEALLOCATOR (a_list); return; }
void (stackbuf_erase) (SCL_stackbuf_t a_stackbuf) { if (a_stackbuf->block != NULL) { SCL_DEALLOCATOR (a_stackbuf->block); a_stackbuf->block = NULL; } }
void (stackbuf_del) (SCL_stackbuf_t a_stackbuf) { if (a_stackbuf->block != NULL) { (void)(*a_stackbuf->putfn) (a_stackbuf->block, a_stackbuf->blen); } SCL_DEALLOCATOR (a_stackbuf); }
int (stackbuf_pull_alloc) ( SCL_stackbuf_t a_stackbuf, void** a_data, size_t a_len ) { int count = 0; S_block_t* block; size_t blen; char* dst; const char* src; dst = SCL_ALLOCATOR (a_len); if (dst == NULL) return SCL_NOMEM; *a_data = dst; while (a_len > 0) { block = a_stackbuf->block; if (block == NULL) { block = (*a_stackbuf->getfn) (a_stackbuf->blen); if (block == NULL) return count; a_stackbuf->block = (S_block_t*)block; a_stackbuf->nin += 1; } blen = block->size; src = &block->data[blen]; while ((blen > 0) && (a_len > 0)) { *dst++ = *--src; blen -= 1; a_len -= 1; count += 1; } block->size = blen; if (blen == 0) { SCL_DEALLOCATOR (a_stackbuf->block); a_stackbuf->block = NULL; } } return count; }
void (list_erase) (SCL_list_t a_list) { S_node_t* node1 = a_list->head; S_node_t* node2 = a_list->head; while (node1 != NULL) { node2 = node1->succ; SCL_DEALLOCATOR ((void*)node1); node1 = node2; } a_list->head = NULL; a_list->tail = NULL; a_list->count = 0; return; }
void* (list_remove_at) (SCL_list_t a_list, SCL_iterator_t a_iterator) { S_SCL_list_t* const list = a_list; S_node_t* node = (S_node_t*)a_iterator; const void* data; if (SUCC(node) != NULL) PRED(SUCC(node)) = PRED(node); if (PRED(node) != NULL) SUCC(PRED(node)) = SUCC(node); if (list->head == node) list->head = SUCC(node); if (list->tail == node) list->tail = PRED(node); data = node->data; list->count -= 1; SCL_DEALLOCATOR (node); return (void*)data; }
void* (list_pop_back) (SCL_list_t a_list) { const void* data; S_SCL_list_t* const list = a_list; S_node_t* node; S_node_t* tail; node = list->tail; if (node == NULL) return NULL; data = (void*)node->data; tail = PRED(node); if (tail != NULL) SUCC(tail) = NULL; else list->head = NULL; list->tail = tail; list->count -= 1; SCL_DEALLOCATOR (node); return (void*)data; }
void* (list_pop_front) (SCL_list_t a_list) { const void* data; S_SCL_list_t* const list = a_list; S_node_t* node; S_node_t* head; node = list->head; if (node == NULL) return NULL; data = (void*)node->data; head = SUCC(node); if (head != NULL) PRED(head) = NULL; else list->tail = NULL; list->head = head; list->count -= 1; SCL_DEALLOCATOR (node); return (void*)data; }
void* (list_remove) (SCL_list_t a_list, size_t a_index) { S_SCL_list_t* const list = a_list; S_node_t* node = list->head; const void* data; if (list->count <= a_index) return NULL; while (a_index-- > 0) node = SUCC(node); if (SUCC(node) != NULL) PRED(SUCC(node)) = PRED(node); if (PRED(node) != NULL) SUCC(PRED(node)) = SUCC(node); if (list->head == node) list->head = SUCC(node); if (list->tail == node) list->tail = PRED(node); data = node->data; list->count -= 1; SCL_DEALLOCATOR (node); return (void*)data; }
void (symbol_del) (SCL_symbol_t a_symbol) { SCL_DEALLOCATOR (a_symbol); }