static void test_slist (void) { SListEntry* list = NULL; int a, b, c; slist_prepend (&list, &a); slist_prepend (&list, &b); slist_prepend (&list, &c); slist_free (list); }
void test_slist_prepend_to_empty(void) { unsigned long *val = NULL; assert_true(test_slist == NULL); test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_is_empty(test_slist)); val = make_ulong_ptr(9999); assert_true(val != NULL); assert_true(slist_prepend(test_slist, val) == 0); /* Verify */ val = NULL; val = slist_index(test_slist, 0); assert_true(val != NULL); assert_ulong_equal(9999, *val); assert_true(slist_size(test_slist) == 1); slist_free_all(test_slist, NULL); test_slist = NULL; }
void register_html (const char *url, const char *file) { if (!opt.convert_links) return; downloaded_html_files = slist_prepend (downloaded_html_files, file); }
/** * Move entry to the head of the slist. */ bool slist_moveto_head(slist_t *slist, void *key) { if (slist_remove(slist, key)) { slist_prepend(slist, key); return TRUE; } return FALSE; }
void queue_push_head (Queue *queue, void *data) { /* Precondition */ assert(queue != NULL); queue->head = slist_prepend (queue->head, data); if (queue->length == 0) { queue->tail = queue->head; } queue->length++; /* Postcondicion */ assert((int) queue->length == slist_length(queue->head)); }
void register_html (const char *url, const char *file) { if (!downloaded_html_set) downloaded_html_set = make_string_hash_table (0); else if (hash_table_contains (downloaded_html_set, file)) return; /* The set and the list should use the same copy of FILE, but the slist interface insists on strduping the string it gets. Oh well. */ string_set_add (downloaded_html_set, file); downloaded_html_list = slist_prepend (downloaded_html_list, file); }
void test_slist_prepend_to_existing(void) { unsigned long *val; unsigned long old_size; old_size = slist_size(test_slist); val = make_ulong_ptr(7777); assert_true(slist_prepend(test_slist, val) == 0); /* Verify */ val = NULL; val = slist_index(test_slist, 0); assert_ulong_equal(7777, *val); assert_true((old_size + 1) == slist_size(test_slist)); }
void archive(struct file_info_t *info, struct file_entry_t *entry) { Set *hash_set = trie_lookup(info->hash_trie, entry->hash); if (hash_set == TRIE_NULL) { /* Otherwise, the value needs a new list */ hash_set = set_new(&pointer_hash, &pointer_equal); slist_prepend(&info->duplicates, hash_set); trie_insert(info->hash_trie, entry->hash, hash_set); } if (!set_insert(hash_set, entry)) { #ifndef NDEBUG fprintf(stderr, "[DEBUG] '%s' (extra file)\n", entry->path); #endif } }
/* * Alternate version that allows two possible names to be specified. * Tile/object layers have different node names ("layer" vs "objectgroup"), * but their order needs to be preserved. This method is a workaround * for that. */ SList *get_children_for_either_name(xmlNode *parent, char *name1, char *name2) { SList *list = NULL; if(!parent->children) return list; xmlNode *child = parent->children->next; while (child) { if(streq((const char*)child->name, name1) || streq((const char*)child->name, name2)) { list = slist_prepend(list, child); } child = child->next; } return list; }
static struct device *open_device(int joystick_index) { // If the device is already open, just up its count and return it for (struct slist *iter = device_list; iter; iter = iter->next) { struct device *d = iter->data; if (d->joystick_index == joystick_index) { d->open_count++; return d; } } // Otherwise open and throw it on the list SDL_Joystick *j = SDL_JoystickOpen(joystick_index); if (!j) return NULL; struct device *d = xmalloc(sizeof(*d)); d->joystick_index = joystick_index; d->joystick = j; d->num_axes = SDL_JoystickNumAxes(j); d->num_buttons = SDL_JoystickNumButtons(j); d->open_count = 1; device_list = slist_prepend(device_list, d); return d; }
void aho_corasick_goto_set(aho_corasick_state_t *from_state, unsigned char symbol, aho_corasick_state_t *to_state) { aho_corasick_labeled_edge_t *edge; switch (from_state->_transitions.type) { case AHO_CORASICK_DENSE_TRANSITIONS: from_state->_transitions.data.array[symbol] = to_state; return; case AHO_CORASICK_SPARSE_TRANSITIONS: edge = xalloc(sizeof(aho_corasick_labeled_edge_t)); if (edge == NULL) { /* fixme: check memory allocation! */ } edge->label = symbol; edge->state = to_state; if (slist_prepend(from_state->_transitions.data.slist, edge) < 0) { /* fixme: check memory allocation! */ } return; } }
int main(int argc, char *argv[]) { SList *l1=NULL, *l2=NULL, *l3=NULL; int i; l1 = slist_prepend(l1, 96); l1 = slist_prepend(l1, 39); l1 = slist_prepend(l1, 28); l1 = slist_prepend(l1, 65); l1 = slist_prepend(l1, 61); l1 = slist_prepend(l1, 00); l1 = slist_prepend(l1, 34); l1 = slist_prepend(l1, 21); l1 = slist_prepend(l1, 43); l1 = slist_prepend(l1, 48); l2 = slist_prepend(l2, 71); l2 = slist_prepend(l2, 00); l2 = slist_prepend(l2, 02); l2 = slist_prepend(l2, 62); l2 = slist_prepend(l2, 22); l2 = slist_prepend(l2, 14); l2 = slist_prepend(l2, 59); l2 = slist_prepend(l2, 28); l2 = slist_prepend(l2, 71); l2 = slist_prepend(l2, 21); l2 = slist_prepend(l2, 89); l2 = slist_prepend(l2, 94); l3 = slist_prepend(l3, 11); l3 = slist_prepend(l3, 81); l3 = slist_prepend(l3, 99); l3 = slist_prepend(l3, 47); l3 = slist_prepend(l3, 72); l3 = slist_prepend(l3, 79); l3 = slist_prepend(l3, 30); l3 = slist_prepend(l3, 66); l3 = slist_prepend(l3, 96); printf("len(l1) = %i\n", slist_length(l1)); printf("len(l2) = %i\n", slist_length(l2)); printf("len(l3) = %i\n", slist_length(l3)); puts(""); printf("l1 = "); printlist(l1); printf("l2 = "); printlist(l2); printf("l3 = "); printlist(l3); puts(""); /* NOTA: Si tu función concat modifica las listas pasadas (es decir, hace que el último nodo de la primera apunte al primero de la segunda), vas a obtener resultados distintos ya que l1 se estaría modificando. Cambiar el argumento 'l1' por 'clonar(l1)' para que no se modifique la lista. */ printf("l1 ++ l2 = "); printlist(slist_concat(l1, l2)); printf("l1 ++ [] = "); printlist(slist_concat(l1, NULL)); printf("[] ++ l2 = "); printlist(slist_concat(NULL, l2)); puts(""); /* Si tu intersect cambia las listas, hacer lo mismo explicado para concat.. */ printf("l1 <inter> l2 = "); printlist(slist_intersect(l1, l2)); printf("l1 <inter> l3 = "); printlist(slist_intersect(l1, l3)); puts(""); // slist_sort(l1,icmpM); printf("sort(l1) = "); printlist(slist_sort(l1,icmpM)); puts(""); /* NOTA: Si tu lista quedó ordenada al revés, o no queda ordenada puede ser por confusiones en como opera la función de comparación. Lo que debe cumplir la función de comparación es: icmp(a, b) > 0 si y solo si a > b icmp(a, b) == 0 si y solo si a == b icmp(a, b) < 0 si y solo si a < b Los valores no son necesariamente 1 y -1. */ return 0; }