Esempio n. 1
0
static void range_nonatomic_test(void *db, int num, int vsiz, int batch,
			unsigned int seed)
{
	TCADB *adb = db;
	struct keygen keygen;
	TCLIST *args = tclistnew();
	char start_key[KEYGEN_PREFIX_SIZE + 1];
	char max[100];
	char end_key[KEYGEN_PREFIX_SIZE + 1];

	keygen_init(&keygen, seed);

	keygen_prefix(&keygen, start_key);
	sprintf(max, "%d", batch);
	keygen_prefix(&keygen, end_key);
	end_key[KEYGEN_PREFIX_SIZE - 1] = '-' + 1;

	tclistpush2(args, start_key);
	tclistpush2(args, max);
	tclistpush2(args, end_key);

	while (1) {
		TCLIST *recs;
		int num_recs;

		recs = do_tcadbmisc(adb, "range", args);
		num_recs = tclistnum(recs) / 2;
		if (!num_recs)
			break;

		check_records(recs, &keygen, vsiz, num < batch ? num : batch);
		/* overwrite start_key by the last one + '\0' */
		tclistover(args, 0, tclistval2(recs, 2 * (num_recs - 1)), KEYGEN_KEY_SIZE + 1);
		tclistdel(recs);
		num -= num_recs;
	}
	if (debug && num)
		die("Unexpected record num: %d", num);

	tclistdel(args);
}
Esempio n. 2
0
void main () {

  uint32_t key = 123;
  const char *val = "abcdefkrnglrg";

  // Make a new tree
  TCTREE *tree = tctreenew();

  // Put an integer key
  tctreeput(tree, &key, sizeof(key), val, strlen(val));
  
  // Put a different key
  key = 122;
  tctreeput(tree, &key, sizeof(key), val, strlen(val));
  
  // Put the same key twice
  tctreeput(tree, &key, sizeof(key), val, strlen(val));

  // Put the same key but keep the old value
  tctreeputkeep(tree, &key, sizeof(key), val, strlen(val));

  // Get back a value
  int size;
  void *newVal = tctreeget(tree, &key, sizeof(key), &size);
  printf("Got value %s\n", newVal);

  // Create an iterator
  tctreeiterinit(tree);

  // Walk the tree
  tctreeiternext(tree, &size);
  tctreeiternext(tree, &size);
  tctreeiternext(tree, &size);

  // Clear the tree
  tctreeclear(tree);

  // Put one value back in the tree to make sure it's freed on delete 
  tctreeput(tree, &key, sizeof(key), val, strlen(val));

  // Delete the tree
  tctreedel(tree);

  // Make a list
  TCLIST *list = tclistnew();

  // Push a few times
  tclistpush(list, &key, sizeof(key));
  key += 1;
  tclistpush(list, &key, sizeof(key));
  key += 1;
  tclistpush(list, &key, sizeof(key));
 
  // Overwrite an existing element
  tclistover(list, 1, &key, sizeof(key));

  // Get a value
  tclistval(list, 2, &size);

  // Remove some values
  newVal = tclistremove(list, 2, &size);
  free(newVal);
  newVal = tclistremove(list, 0, &size);
  free(newVal);

  // Free the whole list
  tclistdel(list);
}
Esempio n. 3
0
 void set(const Value & value, int index)
 {
   tclistover(list_, index, ser::cptr(value), ser::len(value));
 }