void quickSort(struct element data[], long left, long right) { struct element temp = data[left]; long ptr = left; long i = left + 1, j = right; if(key_compare(data[i], temp)) { data[ptr] = data[i]; ptr = i; } while(i!=j) { if(!key_compare(data[i], temp)) { j--; } else { data[ptr] = data[j]; ptr = j; while(key_compare(data[i], temp) && i != j) { i++; } data[ptr] = data[i]; ptr = i; } } data[ptr] = temp; if(left < ptr - 1) quickSort(data, left, ptr - 1); if(ptr + 1 < right) quickSort(data, ptr + 1, right); }
int insert_nonfull(b_tree** root, i_primario* k){ int i = (*root)->i_counter; if ((*root)->leaf == 1){ //CASO LEAF FUNCIONA, CHECAR CASO NÃO-LEAF while ( i >= 0 ){ if ((*root)->index[i] != NULL){ if ( key_compare((*root)->index[i]->key, k->key) == 1){ (*root)->index[i+1] = (*root)->index[i]; }else{ break; } } i--; } i++; (*root)->index[i] = k; (*root)->i_counter++; return FUNCTION_OK; }else{ //printf("not leaf => i_counter: %d // ", (*root)->i_counter); for(i = (*root)->i_counter - 1; i >= 0; i--){ if((*root)->index[i] != NULL){ if (key_compare((*root)->index[i]->key, k->key) == 2){ //i++; break; } } } i++; if((*root)->branches[i]->i_counter == (ORDEM-1)){ splitting(root, i, &((*root)->branches[i]) ); insert_nonfull(root, k); }else{ insert_nonfull(&((*root)->branches[i]) , k); } } return FUNCTION_OK; }
LinphoneSubscribePolicy __policy_str_to_enum(const char* pol){ if (key_compare("accept",pol)==0){ return LinphoneSPAccept; } if (key_compare("deny",pol)==0){ return LinphoneSPDeny; } if (key_compare("wait",pol)==0){ return LinphoneSPWait; } ms_warning("Unrecognized subscribe policy: %s",pol); return LinphoneSPWait; }
static void macro_define_object_internal (struct macro_source_file *source, int line, const char *name, const char *replacement, enum macro_special_kind kind) { struct macro_table *t = source->table; struct macro_key *k = NULL; struct macro_definition *d; if (! t->redef_ok) k = check_for_redefinition (source, line, name, macro_object_like, 0, 0, replacement); /* If we're redefining a symbol, and the existing key would be identical to our new key, then the splay_tree_insert function will try to delete the old definition. When the definition is living on an obstack, this isn't a happy thing. Since this only happens in the presence of questionable debug info, we just ignore all definitions after the first. The only case I know of where this arises is in GCC's output for predefined macros, and all the definitions are the same in that case. */ if (k && ! key_compare (k, name, source, line)) return; k = new_macro_key (t, name, source, line); d = new_macro_definition (t, macro_object_like, kind, 0, replacement); splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d); }
void macro_define_function (struct macro_source_file *source, int line, const char *name, int argc, const char **argv, const char *replacement) { struct macro_table *t = source->table; struct macro_key *k = NULL; struct macro_definition *d; if (! t->redef_ok) k = check_for_redefinition (source, line, name, macro_function_like, argc, argv, replacement); /* See comments about duplicate keys in macro_define_object. */ if (k && ! key_compare (k, name, source, line)) return; /* We should also check here that all the argument names in ARGV are distinct. */ k = new_macro_key (t, name, source, line); d = new_macro_definition (t, macro_function_like, argc, argv, replacement); splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d); }
bool CipherExample (KCipher * cipher) { uint8_t cipher_text [16]; rc_t rc; bool passed_key; bool passed_block; memset (cipher_text, 0, sizeof cipher_text); rc = KCipherSetEncryptKey (cipher, b.key, 128/8); if (rc) ; else { passed_key = key_compare (&b.key_schedule, cipher->encrypt_key); rc = KCipherEncrypt (cipher, b.plain, cipher_text); if (rc) ; else { passed_block = block_compare (b.cipher, cipher_text); } } if (rc) { STSMSG (1,("Could not run test")); return false; } return passed_key && passed_block; }
/* Move the cursor so that it points to an entry near pKey. ** Return a success code. ** ** *pRes<0 The cursor is left pointing at an entry that ** is smaller than pKey or if the table is empty ** and the cursor is therefore left point to nothing. ** ** *pRes==0 The cursor is left pointing at an entry that ** exactly matches pKey. ** ** *pRes>0 The cursor is left pointing at an entry that ** is larger than pKey. */ static int memRbtreeMoveto( RbtCursor* pCur, const void *pKey, int nKey, int *pRes ){ BtRbNode *pTmp = 0; pCur->pNode = pCur->pTree->pHead; *pRes = -1; while( pCur->pNode && *pRes ) { *pRes = key_compare(pCur->pNode->pKey, pCur->pNode->nKey, pKey, nKey); pTmp = pCur->pNode; switch( *pRes ){ case 1: /* cursor > key */ pCur->pNode = pCur->pNode->pLeft; break; case -1: /* cursor < key */ pCur->pNode = pCur->pNode->pRight; break; } } /* If (pCur->pNode == NULL), then we have failed to find a match. Set * pCur->pNode to pTmp, which is either NULL (if the tree is empty) or the * last node traversed in the search. In either case the relation ship * between pTmp and the searched for key is already stored in *pRes. pTmp is * either the successor or predecessor of the key we tried to move to. */ if( !pCur->pNode ) pCur->pNode = pTmp; pCur->eSkip = SKIP_NONE; return SQLITE_OK; }
/* The macro tree comparison function, typed for the splay tree library's happiness. */ static int macro_tree_compare (splay_tree_key untyped_key1, splay_tree_key untyped_key2) { struct macro_key *key1 = (struct macro_key *) untyped_key1; struct macro_key *key2 = (struct macro_key *) untyped_key2; return key_compare (key1, key2->name, key2->start_file, key2->start_line); }
splaytree_impl( bool unique, Iterator b, Iterator e , const key_compare &cmp = key_compare() , const value_traits &v_traits = value_traits()) : tree_type(cmp, v_traits) { if(unique) this->insert_unique(b, e); else this->insert_equal(b, e); }
/* Position node in btree so that key might be inside */ static node_buf* record_find_node(btree* tree, void *key) { int start, end, mid, comp; // components of a binary search void *p = NULL; char curr_key[tree->head.max_key_len]; // The current key under examination hfsp_key_read readkey = tree->kread; hfsp_key_compare key_compare = tree->kcomp; UInt32 index; node_buf* node = btree_node_by_index(tree, tree->head.root); if (!node) HFSP_ERROR(-1, "record_find_node: Cant position to root node"); while (node->desc.kind == HFSP_NODE_NDX) { mid = start = 0; end = node->desc.num_rec; comp = -1; while (start < end) { mid = (start + end) >> 1; p = btree_key_by_index(tree, node, mid); if (!p) HFSP_ERROR(-1, "record_find_node: unexpected error"); p = readkey (p, curr_key); if (!p) HFSP_ERROR(-1, "record_find_node: unexpected error"); comp = key_compare(curr_key, key); if (comp > 0) start = mid + 1; else if (comp < 0) end = mid; else break; } if (!p) // Empty tree, fascinating ... HFSP_ERROR(-1, "record_find_node: unexpected empty node"); if (comp < 0) // mmh interesting key is before this key ... { if (mid == 0) return NULL; // nothing before this key .. p = btree_key_by_index(tree, node, mid-1); if (!p) HFSP_ERROR(-1, "record_find_node: unexpected error"); p = readkey (p, curr_key); if (!p) HFSP_ERROR(-1, "record_find_node: unexpected error"); } index = bswabU32_inc(p); node = btree_node_by_index(tree, index); } return node; // go on and use the found node fail: return NULL; }
static key_list_node_t* key_list_get_node(key_list_t *list,key_t key) { key_list_node_t *current = list->header; while (current != NULL) { if (key_compare(key,current->key)) { return current; } current = current->next; } return NULL; }
bool KeyExpansion (KCipher * cipher, const key_expansion * ke) { rc_t rc; rc = KCipherSetEncryptKey (cipher, ke->key, ke->Nk); if (rc) { STSMSG (1,("Could not run test")); return false; } else { return (key_compare (&ke->key_schedule, cipher->encrypt_key)); } }
static int memRbtreeKeyCompare(RbtCursor* pCur, const void *pKey, int nKey, int nIgnore, int *pRes) { assert(pCur); if( !pCur->pNode ) { *pRes = -1; } else { if( (pCur->pNode->nKey - nIgnore) < 0 ){ *pRes = -1; }else{ *pRes = key_compare(pCur->pNode->pKey, pCur->pNode->nKey-nIgnore, pKey, nKey); } } return SQLITE_OK; }
elem * get_elem_trolley_aux(elem *e, char *key) { elem *current = e; while (current) { trolley *t = (trolley*)current->box; int action = key_compare(t->key, key); log_info("get_elem_trolley_aux", current, "%p"); log_info("get_elem_trolley_aux", t, "%p"); log_info("get_elem_trolley_aux", action, "%d"); if (action == 0) return current; current = current->next; } return NULL; }
/* search for the given key in the btree. * * returns pointer to memory just after key or NULL * In any case *keyind recives the index where the * key was found (or could be inserted.) */ static void * record_find_key(btree* tree, void* key, int* keyind, UInt16* node_index) { node_buf* buf = record_find_node(tree, key); if (buf) { int comp = -1; int start = 0; // components of a binary search int end = buf->desc.num_rec; int mid = -1; void *p = NULL; char curr_key[tree->head.max_key_len]; hfsp_key_read readkey = tree->kread; hfsp_key_compare key_compare = tree->kcomp; while (start < end) { mid = (start + end) >> 1; p = btree_key_by_index(tree, buf, mid); if (!p) HFSP_ERROR(-1, "record_init_key: unexpected error"); p = readkey (p, curr_key); if (!p) HFSP_ERROR(-1, "record_init_cat_key: unexpected error"); comp = key_compare(curr_key, key); if (comp > 0) start = mid + 1; else if (comp < 0) end = mid; else break; } if (!p) // Empty tree, fascinating ... HFSP_ERROR(ENOENT, "record_init_key: unexpected empty node"); *keyind = mid; *node_index = buf->index; if (!comp) // found something ... return p; } HFSP_ERROR(ENOENT, NULL); fail: return NULL; }
/* find_index() - performs binary search of list of keys in node * to find either the index of the existing key, or the insertion * point of a new key. Returns nonnegative index of insertion point * if new key, or -(index+1) for existing key found at index * * TODO: fill in the binary search while loop */ int find_index(nodekey key, p_tnode pnode) { /* find in between */ int icmp, L = 0, R = pnode->nkeys-1;//, M; //int ibetween = 0; /* index to return */ /* TODO: complete binary search; * use key_compare() to compare two keys. */ while (L <= R) { icmp = key_compare(key, pnode->keys[L]); //icmp<0: key is before than pnode->keys[] if (icmp == 0) { return -(L+1); } else if (icmp<0) { return L; } else { L++; } } return L; }
int key_seek(b_tree* data, char* trigger){ /* RECEBE: Endereço da b-tree a ser percorrida Chave (string) RETORNA: Linha associada à chave, caso encontrada ERROR_DATA, caso não encontrada ERROR_STREAM, caso bad input */ short int code; short int counter = 0; b_tree* source = data; //Só verificando que tá tudo no lugar if (trigger == NULL) return ERROR_STREAM; if (data == NULL) return ERROR_DATA; for (counter = 0; counter < ORDEM - 1; counter++){ //if (data->branches[counter] != NULL) //key_seek(data->branches[counter], trigger); code = key_compare(source->index[counter]->key, trigger); //CASO I: trigger pertence ao nó presente if (code == 0) return source->index[counter]->line; //CASE II: trigger é menor que a chave presente (procurar filho anterior) if (code == 1) return key_seek(source->branches[counter], trigger); } //CASE III: trigger é maior que todos os elementos do nó (buscar último filho) return key_seek(source->branches[ORDEM - 1], trigger); }
// Finds an element with key equivalent to key. iterator find(const key_type& k) { return find([&](const value_type& pair) { return key_compare()(pair.first, k); }); }
// // Observers // key_compare key_comp() const { return key_compare(); }
bool ExampleVector (KCipher * cipher, const example_vectors * ev) { uint8_t cipher_text [16]; uint8_t plain_text [16]; uint32_t Nk; rc_t rc; bool passed_enckey; bool passed_deckey; bool passed_enc; bool passed_dec; switch (ev->key_enc.rounds) { default: STSMSG (1,("Bad test vector")); return false; case 10: Nk = 16; break; case 12: Nk = 24; break; case 14: Nk = 32; break; } memset (cipher_text, 0, sizeof cipher_text); memset (plain_text, 0, sizeof plain_text); rc = KCipherSetEncryptKey (cipher, ev->key, Nk); if (rc) ; else { passed_enckey = key_compare (&ev->key_enc, cipher->encrypt_key); rc = KCipherSetDecryptKey (cipher, ev->key, Nk); if (rc) ; else { #if COMPARE_INV_CIPHER passed_deckey = key_compare (&ev->key_dec, cipher->decrypt_key); #endif #if COMPARE_EQ_INV_CIPHER passed_deckey = key_compare (&ev->key_dec_alt, cipher->decrypt_key); #endif rc = KCipherEncrypt (cipher, ev->plain, cipher_text); if (rc) ; else { passed_enc = block_compare (ev->cipher, cipher_text); rc = KCipherDecrypt (cipher, ev->cipher, plain_text); if (rc) ; else { passed_dec = block_compare (ev->plain, plain_text); } } } } if (rc) { STSMSG (1,("Could not run test")); return false; } return passed_enckey && passed_deckey && passed_enc && passed_dec; }
static int report_compare(struct report *a, struct report *b) { return (key_compare(a->key, a->keylen, b->key, b->keylen)); }
avltree_impl( bool unique, Iterator b, Iterator e , const key_compare &cmp = key_compare() , const value_traits &v_traits = value_traits()) : tree_type(unique, b, e, cmp, v_traits) {}
//! @copydoc ::geofeatures_boost::intrusive::rbtree::rbtree(const key_compare &,const value_traits &) explicit set_impl( const key_compare &cmp = key_compare() , const value_traits &v_traits = value_traits()) : tree_type(cmp, v_traits) {}
set_impl( Iterator b, Iterator e , const key_compare &cmp = key_compare() , const value_traits &v_traits = value_traits()) : tree_type(true, b, e, cmp, v_traits) {}
/** * Computes shortest path. * * @return bool successful */ bool Planner::_compute() { if (_open_list.empty()) return false; KeyCompare key_compare; int attempts = 0; Map::Cell* u; pair<double,double> k_old; pair<double,double> k_new; Map::Cell** nbrs; double g_old; double tmp_g, tmp_rhs; while (( ! _open_list.empty() && key_compare(_open_list.begin()->first, _k(_start))) || ! Math::equals(_rhs(_start), _g(_start))) { // Reached max steps, quit if (++attempts > Planner::MAX_STEPS) return false; u = _open_list.begin()->second; k_old = _open_list.begin()->first; k_new = _k(u); tmp_rhs = _rhs(u); tmp_g = _g(u); if (key_compare(k_old, k_new)) { _list_update(u, k_new); } else if (Math::greater(tmp_g, tmp_rhs)) { _g(u, tmp_rhs); tmp_g = tmp_rhs; _list_remove(u); nbrs = u->nbrs(); for (unsigned int i = 0; i < Map::Cell::NUM_NBRS; i++) { if (nbrs[i] != NULL) { if (nbrs[i] != _goal) { _rhs(nbrs[i], min(_rhs(nbrs[i]), _cost(nbrs[i], u) + tmp_g)); } _update(nbrs[i]); } } } else { g_old = tmp_g; _g(u, Math::INF); // Perform action for u if (u != _goal) { _rhs(u, _min_succ(u).second); } _update(u); nbrs = u->nbrs(); // Perform action for neighbors for (unsigned int i = 0; i < Map::Cell::NUM_NBRS; i++) { if (nbrs[i] != NULL) { if (Math::equals(_rhs(nbrs[i]), (_cost(nbrs[i], u) + g_old))) { if (nbrs[i] != _goal) { _rhs(nbrs[i], _min_succ(nbrs[i]).second); } } _update(nbrs[i]); } } } } return true; }