Beispiel #1
0
static Node *node_put(Node *h, Key_T key, Val_T val) {
    if (h == NULL) {
        h = malloc(sizeof(Node));
        node_init2(h, key, val);
        return h;
    }
    int i;
    if (node_isLeaf(h)) {
        for (i = 0; i != h->num - 1; i++) {
            int cmp = keycmp(key, h->keys[i]);
            if (cmp < 0) {
                node_doPut(h, i, key, val);
            }
        
        }
    }
    for (i = 0; i != h->num - 1; i++) {
        int cmp = keycmp(key, h->keys[i]);
        if (cmp < 0) {
            h->childs[i] = node_put(h->childs[i], key, val);
            return h;
        } else if (cmp == 0) {
            printf("warning: not support same key=%d\n", key);
            return h;
        }
    }
    h->childs[i] = node_put(h->childs[i], key, val);
    return h;
}
Beispiel #2
0
item *assoc_find(const char *key, const size_t nkey, const uint32_t hv) {
    item *it;
    unsigned int oldbucket;

    if (expanding &&
        (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
    {
        it = old_hashtable[oldbucket];
    } else {
        it = primary_hashtable[hv & hashmask(hashpower)];
    }

    item *ret = NULL;
    int depth = 0;
    while (it) {
        if ((nkey == it->nkey) && (keycmp(key, ITEM_key(it), nkey) )) {
            ret = it;
            break;
        }
        it = it->h_next;
        ++depth;
    }

    total_steps += depth;

    MEMCACHED_ASSOC_FIND(key, nkey, depth);
    return ret;
}
Beispiel #3
0
int main(void)
{
    int one = 1;
    if (*(unsigned char *) &one == 1) {
        printf("little endian\n");
    } else {
        printf("big endian\n");
    }
    const int len = 25;
    unsigned char a[len], b[len];
    DBT ax, bx;
    dbt_init(&ax, a, sizeof(a));
    dbt_init(&bx, b, sizeof(b));
    srand(time(NULL));
    for (int i = 0; i < len; i++) {
        a[i] = rand() & 0xFF;
        for (int j = 0; j < len; j++) {
            b[i] = rand() & 0xFF;
            int tokucmp = toku_keycompare(a, len, b, len);
            int mycmp = keycmp(NULL, &ax, &bx);
            if ((tokucmp < 0) != (mycmp < 0)) {
                doerror(tokucmp, mycmp, a, len, b, len);
            }
            if ((tokucmp == 0) != (mycmp == 0)) {
                doerror(tokucmp, mycmp, a, len, b, len);
            }
            if ((tokucmp > 0) != (mycmp > 0)) {
                doerror(tokucmp, mycmp, a, len, b, len);
            }
        }
    }
    return 0;
}
Beispiel #4
0
struct mesh_rte* rtb_find(struct mesh_rtb* tb, keytype k){
	struct mesh_rte* it;
	WALK_LIST(it, (tb->hooks), struct mesh_rte* ){
		if (keycmp(it->target,k) == 0)return it;
	}
	return NULL;
}
Beispiel #5
0
static Val_T node_get(Node *h, Key_T key) {
    if (h == NULL) {
        return NULL;
    }
    int i;
    for (i = 0; i != h->num - 1; i++) {
        int cmp = keycmp(key, h->keys[i]);
        if (cmp < 0) {
            return node_get(h->childs[i], key);
        } else if (cmp == 0) {
            return h->vals[i];
        } else {
            continue;
        }
    }
    return node_get(h->childs[i], key);
}
Beispiel #6
0
/* merge 2 lists under dummy head item */
list *lmerge (list *p, list *q)
{
      list *r, head;

      for ( r = &head; p && q; )
      {
            if ( keycmp(p, q) < 0 )
            {
                  r = r->next = p;
                  p = p->next;
            }
            else
            {
                  r = r->next = q;
                  q = q->next;
            }
      }
      r->next = (p ? p : q);
      return head.next;
}
Beispiel #7
0
/* true if @key is strictly within @node

   we are looking for possibly non-unique key and it is item is at the edge of
   @node. May be it is in the neighbor.
*/
static int znode_contains_key_strict(znode * node	/* node to check key
							 * against */ ,
				     const reiser4_key *
				     key /* key to check */ ,
				     int isunique)
{
	int answer;

	assert("nikita-1760", node != NULL);
	assert("nikita-1722", key != NULL);

	if (keyge(key, &node->rd_key))
		return 0;

	answer = keycmp(&node->ld_key, key);

	if (isunique)
		return answer != GREATER_THAN;
	else
		return answer == LESS_THAN;
}
Beispiel #8
0
static void
join (
     FILE *fp1,
     FILE *fp2 )
{
  struct seq seq1, seq2;
  struct line line;
  int diff, i, j, eof1, eof2;

  /* Read the first line of each file. */
  initseq (&seq1);
  getseq (fp1, &seq1);
  initseq (&seq2);
  getseq (fp2, &seq2);

  while (seq1.count && seq2.count)
    {
      diff = keycmp (&seq1.lines[0], &seq2.lines[0]);
      if (diff < 0)
	{
	  if (print_unpairables_1)
	    prline (&seq1.lines[0]);
	  freeline (&seq1.lines[0]);
	  seq1.count = 0;
	  getseq (fp1, &seq1);
	  continue;
	}
      if (diff > 0)
	{
	  if (print_unpairables_2)
	    prline (&seq2.lines[0]);
	  freeline (&seq2.lines[0]);
	  seq2.count = 0;
	  getseq (fp2, &seq2);
	  continue;
	}

      /* Keep reading lines from file1 as long as they continue to
	 match the current line from file2. */
      eof1 = 0;
      do
	if (!getseq (fp1, &seq1))
	  {
	    eof1 = 1;
	    ++seq1.count;
	    break;
	  }
      while (!keycmp (&seq1.lines[seq1.count - 1], &seq2.lines[0]));

      /* Keep reading lines from file2 as long as they continue to
	 match the current line from file1. */
      eof2 = 0;
      do
	if (!getseq (fp2, &seq2))
	  {
	    eof2 = 1;
	    ++seq2.count;
	    break;
	  }
      while (!keycmp (&seq1.lines[0], &seq2.lines[seq2.count - 1]));

      if (print_pairables)
	{
	  for (i = 0; i < seq1.count - 1; ++i)
	    for (j = 0; j < seq2.count - 1; ++j)
	      prjoin (&seq1.lines[i], &seq2.lines[j]);
	}

      for (i = 0; i < seq1.count - 1; ++i)
	freeline (&seq1.lines[i]);
      if (!eof1)
	{
	  seq1.lines[0] = seq1.lines[seq1.count - 1];
	  seq1.count = 1;
	}
      else
	seq1.count = 0;

      for (i = 0; i < seq2.count - 1; ++i)
	freeline (&seq2.lines[i]);
      if (!eof2)
	{
	  seq2.lines[0] = seq2.lines[seq2.count - 1];
	  seq2.count = 1;
	}
      else
	seq2.count = 0;
    }

  if (print_unpairables_1 && seq1.count)
    {
      prline (&seq1.lines[0]);
      freeline (&seq1.lines[0]);
      while (getline (fp1, &line))
	{
	  prline (&line);
	  freeline (&line);
	}
    }

  if (print_unpairables_2 && seq2.count)
    {
      prline (&seq2.lines[0]);
      freeline (&seq2.lines[0]);
      while (getline (fp2, &line))
	{
	  prline (&line);
	  freeline (&line);
	}
    }

  delseq (&seq1);
  delseq (&seq2);
}