int jlst_in_jlst(j_list *great_list, j_list *to_search, int (*compare_func)(void*, void*)) { j_list *tmpa; j_list *tmpb; j_list *tmpc; int i[2]; tmpa = great_list; i[1] = jlst_length(great_list) - jlst_length(to_search); i[0] = 0; while (tmpa && i[0] <= i[1]) { tmpb = to_search; if (!compare_func(tmpa->data, tmpb->data)) { tmpc = tmpa; while (tmpc && tmpb && !compare_func(tmpc->data, tmpb->data)) { tmpc = tmpc->next; tmpb = tmpb->next; } if (tmpb == NULL) return (i[0]); } i[0]++; tmpa = tmpa->next; } return (-1); }
/* ************************************************************************* * * クイックソート * ************************************************************************* */ void quick_sort (struct profile *p, int start, int end, int (*compare_func) (struct profile *p1, struct profile *p2)) { struct profile tmp, key; int left, right; /* キーを決める */ key = p[(start + end) / 2]; /* 交換するデータを交換する */ left = start; right = end; while (1) { while (compare_func(&key, &p[left]) > 0) left++; while (compare_func(&key, &p[right]) < 0) right--; if (left >= right) break; tmp = p[left]; p[left] = p[right]; p[right] = tmp; } /* 左部分をさらにソート */ if (start < left - 1) quick_sort(p, start, left - 1, compare_func); /* 右部分をさらにソート */ if (end > right + 1) quick_sort(p, right + 1, end, compare_func); }
SList *SList_merge(SList *left, SList *right, SList_CompareFunc compare_func, gpointer user_data){ register SList *merged = SList_create(left->set); register SList swap; g_assert(left->set == right->set); while(!(SList_isempty(left) || SList_isempty(right))){ if(compare_func(left->head->next->data, right->head->next->data, user_data)){ SList_queue(merged, SList_pop(left)); } else { SList_queue(merged, SList_pop(right)); } } SList_join(merged, left); SList_join(merged, right); SList_destroy(left); /* Swap left and merged */ swap.head = left->head; swap.tail = left->tail; left->head = merged->head; left->tail = merged->tail; merged->head = swap.head; merged->tail = swap.tail; return merged; }
static GSList* g_slist_sort_merge (GSList *l1, GSList *l2, GCompareFunc compare_func) { GSList list, *l; l=&list; while (l1 && l2) { if (compare_func(l1->data,l2->data) < 0) { l=l->next=l1; l1=l1->next; } else { l=l->next=l2; l2=l2->next; } } l->next= l1 ? l1 : l2; return list.next; }
MSList *ms_list_insert_sorted(MSList *list, void *data, int (*compare_func)(const void *, const void*)){ MSList *it,*previt=NULL; MSList *nelem; MSList *ret=list; if (list==NULL) return ms_list_append(list,data); else{ nelem=ms_list_new(data); for(it=list;it!=NULL;it=it->next){ previt=it; if (compare_func(data,it->data)<=0){ nelem->prev=it->prev; nelem->next=it; if (it->prev!=NULL) it->prev->next=nelem; else{ ret=nelem; } it->prev=nelem; return ret; } } previt->next=nelem; nelem->prev=previt; } return ret; }
/*=========================================================================== FUNCTION Q_LINEAR_SEARCH DESCRIPTION Given a comparison function, this function traverses the elements in a queue, calls the compare function on each item, and returns a pointer to the current element's link if the user passed compare function returns non-zero on that element. The user compare function should return 0 if the current element is not the element in which the compare function is interested. The user compare function SHOULD NOT dequeue a node. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE A pointer to the found element's queue link. SIDE EFFECTS A pointer to a linked element's link is returned without de-queuing the item. ===========================================================================*/ void *q_linear_search ( q_type *q_ptr, /* Queue to be traversed */ q_compare_func_type compare_func, /* Compare function to be called */ void *compare_val /* Cookie to pass to compare_func */ ) { q_link_type *link_ptr = NULL; /* Link to be returned */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /*------------------------------------------------------------------------- Verify parameters. -------------------------------------------------------------------------*/ ASSERT( NULL != q_ptr ); ASSERT( NULL != compare_func ); /*------------------------------------------------------------------------- Check that the queue is initialized. Works if FEATURE_QUEUE_NO_STRICT_CHECK is turned off. -------------------------------------------------------------------------*/ QUEUE_CHECK_INIT( q_ptr ); link_ptr = q_check( q_ptr ); while( NULL != link_ptr ) { if( 0 != compare_func( link_ptr, compare_val ) ) { break; } link_ptr = q_next( q_ptr, link_ptr ); } /* while */ return link_ptr; } /* q_linear_search() */
bctbx_list_t* bctbx_list_insert_sorted(bctbx_list_t* list, void *data, bctbx_compare_func compare_func) { bctbx_list_t* it,*previt=NULL; bctbx_list_t* nelem; bctbx_list_t* ret=list; if (list==NULL) return bctbx_list_append(list,data); else { nelem=bctbx_list_new(data); for(it=list; it!=NULL; it=it->next) { previt=it; if (compare_func(data,it->data)<=0) { nelem->prev=it->prev; nelem->next=it; if (it->prev!=NULL) it->prev->next=nelem; else { ret=nelem; } it->prev=nelem; return ret; } } previt->next=nelem; nelem->prev=previt; } return ret; }
static gint filelist_compare_indirect(gconstpointer ap, gconstpointer bp, gpointer data) { GCompareFunc compare_func = data; gconstpointer a = *(const gconstpointer*)ap; gconstpointer b = *(const gconstpointer*)bp; return compare_func(a, b); }
/** * @brief Extract Node from single linked list * * @param list * @param compare_func * @param data * * @return pointer to Node or NULL(failled operation) */ Node* single_linked_list_get_Node(SingleLinkedList* list, COMPARE compare_func, void* data) { Node* node = list->head; while (node != NULL) { if (compare_func(node->data, data) == 0) { return node; } node = node->next; } return NULL; }
bctbx_list_t * bctbx_list_remove_custom(bctbx_list_t *first, bctbx_compare_func compare_func, const void *user_data) { bctbx_list_t *cur; bctbx_list_t *elem = first; while (elem != NULL) { cur = elem; elem = elem->next; if (compare_func(cur->data, user_data) == 0) { first = bctbx_list_remove(first, cur->data); } } return first; }
MSList * ms_list_remove_custom(MSList *first, MSCompareFunc compare_func, const void *user_data) { MSList *cur; MSList *elem = first; while (elem != NULL) { cur = elem; elem = elem->next; if (compare_func(cur->data, user_data) == 0) { first = ms_list_remove(first, cur->data); } } return first; }
int jlst_appears(j_list *first_node, void *data, int (*compare_func)(void*, void*)) { j_list *tmp; tmp = first_node; while (tmp) { if (!compare_func(data, tmp->data)) return (1); tmp = tmp->next; } return (0); }
wmem_list_frame_t * wmem_list_find_custom(wmem_list_t *list, const void *data, GCompareFunc compare_func) { wmem_list_frame_t *cur; for (cur = list->head; cur != NULL; cur = cur->next) { if (compare_func(cur->data, data) == 0) { return cur; } } return NULL; }
int compare_pnp_id(struct pnp_id *pos, const char *id) { if (!pos || !id || (strlen(id) != 7)) return 0; if (memcmp(id, "ANYDEVS", 7) == 0) return 1; while (pos) { if (memcmp(pos->id, id, 3) == 0) if (compare_func(pos->id, id) == 1) return 1; pos = pos->next; } return 0; }
ngx_rbtree_node_t * ngx_http_rwd_rbtree_lookup_value(ngx_rbtree_t *rbtree, ngx_rbtree_node_t *target, ngx_http_rwd_rbtree_compare_pt compare_func) { ngx_rbtree_node_t *tmpnode = rbtree->root; while (tmpnode != rbtree->sentinel) { if (compare_func(target, tmpnode) == 0) { return tmpnode; } } return NULL; }
void jlst_del_data(j_list **first_node, void *data, int (*compare_func)(void*, void*)) { int i; j_list *tmp; i = 1; tmp = *first_node; while (tmp) { if (!compare_func(tmp->data, data)) jlst_del_node(first_node, i); tmp = tmp->next; i++; } }
metapixel_match_t search_metapixel_nearest_to (int num_libraries, library_t **libraries, coeffs_union_t *coeffs, metric_t *metric, int x, int y, metapixel_t **forbidden, int num_forbidden, unsigned int forbid_reconstruction_radius, unsigned int allowed_flips, int (*validity_func) (void*, metapixel_t*, unsigned int, int, int), void *validity_func_data) { float best_score = FLT_MAX; metapixel_t *best_fit = 0; unsigned int best_index = (unsigned int)-1; unsigned int best_orientation = 0; compare_func_set_t *compare_func_set = metric_compare_func_set_for_metric(metric); metapixel_match_t match; /* allowed < 0 means we don't know. 0 means not allowed, >0 means allowed. */ int allowed; void check_orientation (metapixel_t *pixel, unsigned int pixel_index, compare_func_t compare_func, unsigned int orientation) { float score; if (allowed == 0) return; score = compare_func(coeffs, pixel, best_score, metric->color_space, metric->weights); if (score < best_score) { if (allowed < 0) allowed = (!metapixel_in_array(pixel, forbidden, num_forbidden) && (validity_func == 0 || validity_func(validity_func_data, pixel, pixel_index, x, y))) ? 1 : 0; assert(allowed >= 0); if (allowed) { best_score = score; best_fit = pixel; best_index = pixel_index; best_orientation = orientation; } } }
void e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id) { int flags; ECanvas *canvas; ECanvasSelectionInfo *info; GList *list; g_return_if_fail(item != NULL); g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); g_return_if_fail(item->canvas != NULL); g_return_if_fail(E_IS_CANVAS(item->canvas)); flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA; canvas = E_CANVAS(item->canvas); for (list = canvas->selection; list; list = g_list_next(list)) { info = list->data; if (info->item == item) { ECanvasItemSelectionCompareFunc compare_func; compare_func = (ECanvasItemSelectionCompareFunc)g_object_get_data(G_OBJECT(info->item), "ECanvasItem::selection_compare_callback"); if (compare_func(info->item, info->id, id, 0) == 0) { ECanvasItemSelectionFunc func; func = (ECanvasItemSelectionFunc) g_object_get_data(G_OBJECT(info->item), "ECanvasItem::selection_callback"); if (func) func(info->item, flags, info->id); canvas->selection = g_list_remove_link(canvas->selection, list); if (canvas->cursor == info) canvas->cursor = NULL; g_message ("ECANVAS: removing info: item %p, info %p", info->item, info->id); g_object_unref (info->item); g_free(info); g_list_free_1(list); break; } } } }
dlist* find_list_element_by_compare( dlist *destlist, list_element element, list_ele_compare compare_func ) { dlist *listitem; ASSERT( NULL != destlist ); listitem = destlist; listitem = listitem->next; for( ; NULL != listitem; listitem = listitem->next ) { if( 0 == compare_func( listitem->info, element ) ) { return listitem->info; } } return NULL; }
static fluid_list_t* fluid_list_sort_merge(fluid_list_t *l1, fluid_list_t *l2, fluid_compare_func_t compare_func) { fluid_list_t list, *l; l = &list; while (l1 && l2) { if (compare_func(l1->data,l2->data) < 0) { l = l->next = l1; l1 = l1->next; } else { l = l->next = l2; l2 = l2->next; } } l->next= l1 ? l1 : l2; return list.next; }
/*=========================================================================== FUNCTION Q_LINEAR_SEARCH DESCRIPTION Given a comparison function, this function traverses the elements in a queue, calls the compare function, and returns a pointer to the current element being compared if the user passed compare function returns non zero. The user compare function should return 0 if the current element is not the element in which the compare function is interested. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. The user's queue elements must have q_link_type as the first element of the queued structure. RETURN VALUE A pointer to the found element SIDE EFFECTS None. ===========================================================================*/ void* q_linear_search( q_type *q_ptr, q_compare_func_type compare_func, void *compare_val ) { q_generic_item_type *item_ptr = NULL; item_ptr = (q_generic_item_type*)q_check( q_ptr ); while( item_ptr != NULL ) { if( compare_func( item_ptr, compare_val ) != 0 ) { return item_ptr; } item_ptr = (q_generic_item_type*)q_next( q_ptr, &item_ptr->link ); } /* END while traversing the queue */ return NULL; } /* END q_linear_search */
int ndi_fmc_entry_error(dev_info_t *dip, int flag, ddi_fm_error_t *derr, const void *bus_err_state) { int status, fatal = 0, nonfatal = 0; ndi_fmc_t *fcp = NULL; ndi_fmcentry_t *fep; struct i_ddi_fmhdl *fmhdl; ASSERT(flag == DMA_HANDLE || flag == ACC_HANDLE); fmhdl = DEVI(dip)->devi_fmhdl; ASSERT(fmhdl); status = DDI_FM_UNKNOWN; if (flag == DMA_HANDLE && DDI_FM_DMA_ERR_CAP(fmhdl->fh_cap)) { fcp = fmhdl->fh_dma_cache; ASSERT(fcp); } else if (flag == ACC_HANDLE && DDI_FM_ACC_ERR_CAP(fmhdl->fh_cap)) { fcp = fmhdl->fh_acc_cache; ASSERT(fcp); } if (fcp != NULL) { /* * Check active resource entries */ mutex_enter(&fcp->fc_lock); for (fep = fcp->fc_head; fep != NULL; fep = fep->fce_next) { ddi_fmcompare_t compare_func; /* * Compare captured error state with handle * resources. During the comparison and * subsequent error handling, we block * attempts to free the cache entry. */ compare_func = (flag == ACC_HANDLE) ? i_ddi_fm_acc_err_cf_get((ddi_acc_handle_t) fep->fce_resource) : i_ddi_fm_dma_err_cf_get((ddi_dma_handle_t) fep->fce_resource); if (compare_func == NULL) /* unbound or not FLAGERR */ continue; status = compare_func(dip, fep->fce_resource, bus_err_state, fep->fce_bus_specific); if (status == DDI_FM_UNKNOWN || status == DDI_FM_OK) continue; if (status == DDI_FM_FATAL) ++fatal; else if (status == DDI_FM_NONFATAL) ++nonfatal; /* Set the error for this resource handle */ if (flag == ACC_HANDLE) { ddi_acc_handle_t ap = fep->fce_resource; i_ddi_fm_acc_err_set(ap, derr->fme_ena, status, DDI_FM_ERR_UNEXPECTED); ddi_fm_acc_err_get(ap, derr, DDI_FME_VERSION); derr->fme_acc_handle = ap; } else { ddi_dma_handle_t dp = fep->fce_resource; i_ddi_fm_dma_err_set(dp, derr->fme_ena, status, DDI_FM_ERR_UNEXPECTED); ddi_fm_dma_err_get(dp, derr, DDI_FME_VERSION); derr->fme_dma_handle = dp; } } mutex_exit(&fcp->fc_lock); } return (fatal ? DDI_FM_FATAL : nonfatal ? DDI_FM_NONFATAL : DDI_FM_UNKNOWN); }
MSList *ms_list_find_custom(MSList *list, int (*compare_func)(const void *, const void*), const void *user_data){ for(;list!=NULL;list=list->next){ if (compare_func(list->data,user_data)==0) return list; } return NULL; }
void e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id) { int flags; ECanvas *canvas; ECanvasSelectionInfo *info; ECanvasItemSelectionFunc func; GList *list; g_return_if_fail(item != NULL); g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); g_return_if_fail(item->canvas != NULL); g_return_if_fail(E_IS_CANVAS(item->canvas)); flags = E_CANVAS_ITEM_SELECTION_SELECT; canvas = E_CANVAS(item->canvas); if (canvas->cursor) { func = (ECanvasItemSelectionFunc)g_object_get_data(G_OBJECT(canvas->cursor->item), "ECanvasItem::selection_callback"); if (func) func(canvas->cursor->item, flags, canvas->cursor->id); } gnome_canvas_item_grab_focus(item); flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR; for (list = canvas->selection; list; list = g_list_next(list)) { ECanvasSelectionInfo *search; search = list->data; if (search->item == item) { ECanvasItemSelectionCompareFunc compare_func; compare_func = (ECanvasItemSelectionCompareFunc)g_object_get_data(G_OBJECT(search->item), "ECanvasItem::selection_compare_callback"); if (compare_func(search->item, search->id, id, 0) == 0) { canvas->cursor = search; func = (ECanvasItemSelectionFunc)g_object_get_data(G_OBJECT(item), "ECanvasItem::selection_callback"); if (func) func(item, flags, search->id); return; } } } info = g_new(ECanvasSelectionInfo, 1); info->item = item; g_object_ref (info->item); info->id = id; g_message ("ECANVAS: new info (2): item %p, id %p", item, id); func = (ECanvasItemSelectionFunc)g_object_get_data(G_OBJECT(item), "ECanvasItem::selection_callback"); if (func) func(item, flags, id); canvas->selection = g_list_prepend(canvas->selection, info); canvas->cursor = info; }
static SListEntry *slist_sort_internal(SListEntry **list, SListCompareFunc compare_func) { SListEntry *pivot; SListEntry *rover; SListEntry *less_list, *more_list; SListEntry *less_list_end, *more_list_end; /* If there are less than two entries in this list, it is * already sorted */ if (*list == NULL || (*list)->next == NULL) { return *list; } /* The first entry is the pivot */ pivot = *list; /* Iterate over the list, starting from the second entry. Sort * all entries into the less and more lists based on comparisons * with the pivot */ less_list = NULL; more_list = NULL; rover = (*list)->next; while (rover != NULL) { SListEntry *next = rover->next; if (compare_func(rover->data, pivot->data) < 0) { /* Place this in the less list */ rover->next = less_list; less_list = rover; } else { /* Place this in the more list */ rover->next = more_list; more_list = rover; } rover = next; } /* Sort the sublists recursively */ less_list_end = slist_sort_internal(&less_list, compare_func); more_list_end = slist_sort_internal(&more_list, compare_func); /* Create the new list starting from the less list */ *list = less_list; /* Append the pivot to the end of the less list. If the less list * was empty, start from the pivot */ if (less_list == NULL) { *list = pivot; } else { less_list_end->next = pivot; } /* Append the more list after the pivot */ pivot->next = more_list; /* Work out what the last entry in the list is. If the more list was * empty, the pivot was the last entry. Otherwise, the end of the * more list is the end of the total list. */ if (more_list == NULL) { return pivot; } else { return more_list_end; } }
belle_sip_list_t* belle_sip_list_find_custom(const belle_sip_list_t* list, belle_sip_compare_func compare_func, const void *user_data){ for(;list!=NULL;list=list->next){ if (compare_func(list->data,user_data)==0) return (belle_sip_list_t *)list; } return NULL; }
texture::settings& texture::settings::compare(texture::compare_func func, texture::compare_mode mode) { return compare_func(func).compare_mode(mode); }
static INLINE void send_delta_events(part_evtlist_t *evlist, memsize_t cur_size, memsize_t prev_size, bool (*compare_func)(memsize_t delta, memsize_t last_sz, memsize_t cur_sz)) { elistdata_t eld_p; mempart_evt_t *reg_event = get_first_event(evlist, &eld_p); while (reg_event != NULL) { struct evt_info_s *evt = ®_event->evt_reg; if (reg_event->onlist == &evlist->active) { memsize_t *delta_p = GET_DELTA_P(evt); CRASHCHECK(delta_p == NULL); initial_delta_conditions_check(reg_event, prev_size, (void *)compare_func); /* if this event has been deactivated, don't send it */ if (evt->flags & evtflags_DEACTIVATE) { deactivate_event(evlist, (part_evt_t *)reg_event); } /* check for event send conditions */ else if ((reg_event->evt_dest.rcvid > 0) && ((compare_func == NULL) || (compare_func(*delta_p, reg_event->evt_data.size, cur_size) == bool_t_TRUE))) { int r; struct sigevent se = evt->sig; // make a local copy /* * if the caller has set evtflags_SIGEV_FLAG_SIGINFO, we * can return some useful information */ if (evt->flags & evtflags_SIGEV_FLAG_SIGINFO) { /* * if the 'cur_size' is too large to fit in the sival_int field * then send back UINT_MAX. This otherwise illegal size value * (because UINT_MAX & (__PAGESIZE - 1) != 0) will be an indication * to the event receiver that o information was provided and * that they need to request the current size if they need it */ if (cur_size > UINT_MAX) { se.sigev_value.sival_int = UINT_MAX; } else { se.sigev_value.sival_int = (_Uint32t)cur_size; } } r = apm_deliver_event(®_event->evt_dest, &se); if (r == EOK) reg_event->undeliverable_count = 0; else if (r == ESRCH) ++reg_event->undeliverable_count; if ((reg_event->undeliverable_count > ORPHAN_RETRY_COUNT) || (!(evt->flags & evtflags_REARM))) { /* remove the event from the list */ deactivate_event(evlist, (part_evt_t *)reg_event); } else { reg_event->evt_data.size = cur_size; } } } reg_event = get_next_event(evlist, reg_event, &eld_p); } }
static gchar * recursive_compare (struct stat *localtime_stat, const gchar *localtime_content, gsize localtime_content_len, const gchar *file, CompareFiles compare_func, GHashTable *ical_zones, gint deep_level, gchar **fallback) { struct stat file_stat; if (g_stat (file, &file_stat) != 0) return NULL; if (S_ISREG (file_stat.st_mode)) { if (compare_func (localtime_stat, &file_stat, localtime_content, localtime_content_len, file)) { gchar *tz = system_timezone_strip_path_if_valid (file); if (deep_level <= 1 || (ical_zones && g_hash_table_lookup (ical_zones, tz))) { update_fallback (fallback, tz, ical_zones); return NULL; } if (ical_zones && !g_hash_table_lookup (ical_zones, tz)) { g_free (tz); return NULL; } return tz; } else return NULL; } else if (S_ISDIR (file_stat.st_mode)) { GDir *dir = NULL; gchar *ret = NULL; const gchar *subfile = NULL; gchar *subpath = NULL; dir = g_dir_open (file, 0, NULL); if (dir == NULL) return NULL; while ((subfile = g_dir_read_name (dir)) != NULL) { subpath = g_build_filename (file, subfile, NULL); ret = recursive_compare ( localtime_stat, localtime_content, localtime_content_len, subpath, compare_func, ical_zones, deep_level + 1, fallback); g_free (subpath); if (ret != NULL) break; } g_dir_close (dir); return ret; } return NULL; }