示例#1
0
static inline TSTree *TSTree_insert_base(TSTree *root, TSTree *node, const char *key, size_t len, void *value)
{
	assert(len > 0 && "length must > 0.");
	assert(key != NULL && "key must not be NULL.");
	assert(value != NULL && "value must not be NULL.");
	
	if (node == NULL) {
		node = (TSTree *)calloc(1, sizeof(TSTree));
		check_mem(node);

		if (root == NULL) {
			root = node;
		}

		node->splitchar = *key;
	}

	if (*key < node->splitchar) {
		node->low = TSTree_insert_base(root, node->low, key, len, value);
	} else if (*key == node->splitchar) {
		if (len > 1) {
			node->equal = TSTree_insert_base(root, node->equal, key+1, len-1, value);
		} else {
			assert(node->value == NULL && "Duplicate insert into tst.");
			node->value = value;
		}
	} else {
		node->high = TSTree_insert_base(root, node->high, key, len, value);
	}
	return node;
	
error:
	return NULL;
}
示例#2
0
文件: tstree.c 项目: jradix/jrxlcthw
static inline TSTree *TSTree_insert_base(TSTree *root, TSTree *node,
					 const char *key,
					 size_t len,
					 void *value)
{
  if(node == NULL) {
    node = (TSTree *) calloc(1, sizeof(TSTree));

    if(root == NULL) {
      root = node;
    }

    node->splitchar = *key;
  }

  if(*key < node->splitchar) {
    node->low = TSTree_insert_base(root, node->low, key, len, value);
  } else if(*key == node->splitchar) {
    if(len > 1) {
      node->equal = TSTree_insert_base(root, node->equal, key+1, len-1, value);
    } else {
      assert(node->value == NULL && "Duplicate insert into tst.");
      node->value = value;
    }
  } else {
    node->high = TSTree_insert_base(root, node->high, key, len, value);
  }

  return node;
}
示例#3
0
static inline TSTree *TSTree_insert_base(TSTree *root, TSTree *node,
          const char *key, size_t len, void *value)
{
  if(node == NULL) {
    node = (TSTree *) calloc(1, sizeof(TSTree));

    check(node != NULL, "Failed creating node");

    node->values = DArray_create(DEFAULT_DARRAY_SIZE, DEFAULT_DARRAY_SIZE);

    if(root == NULL) root = node;

    node->splitchar = *key;
  }

  if(*key < node->splitchar) {
    node->low = TSTree_insert_base(root, node->low, key, len, value);
  } else if(*key == node->splitchar) {
    if(len > 1) {
      node->equal = TSTree_insert_base(root, node->equal, key + 1, len - 1, value);
    } else {
        DArray_push(node->values, value);
        return node;
        // assert(node->value == NULL && "Duplicate insert into tst.");
    }
  } else {
      node->high = TSTree_insert_base(root, node->high, key, len, value);
  }

  return node;

error:
  return NULL;
}
示例#4
0
TSTree *TSTree_insert(TSTree *node, const char *key, size_t len, void *value) 
{
	assert(len > 0 && "length must > 0.");
	assert(key != NULL && "key must not be NULL.");
	assert(value != NULL && "value must not be NULL.");
	
	return TSTree_insert_base(node, node, key, len, value);
}
示例#5
0
TSTree *TSTree_insert(TSTree *node, const char *key, size_t len, void *value)
{

  check(key != NULL, "Key can't be NULL");
  check(value != NULL, "Value can't be NULL");
  check(len > 0, "Size can't be 0 or negative");

  return TSTree_insert_base(node, node, key, len, value);

error:
  return NULL;
}
示例#6
0
文件: tstree.c 项目: jradix/jrxlcthw
TSTree *TSTree_insert(TSTree *node, const char *key, size_t len, void *value)
{
  return TSTree_insert_base(node, node, key, len, value);
}