Example #1
0
int tbl_put(table_t *ct, connection_t *c) {
	int index = tbl_hash(c->client, c->server);

	if (ct->curr_size <= MAX_CONNECTIONS) {
		lst_add(ct->map[index], lst_create(c));
		ct->curr_size++;

		return 0;
	}

	return 1;
}
Example #2
0
void*
tbl_get(tbl_t* tt, char* key)
{
  uint32_t index = tbl_hash(key) % tt->nalloc;
  llist_t* ll = tt->buckets[index];

  int i;
  for (i = 0; i < ll->size; ++i)
    if (strcmp(pair_key(llist_at(ll, i)), key) == 0)
      return pair_value(llist_at(ll, i));

  return NULL;
}
Example #3
0
bool
tbl_contains(tbl_t* tt, char* key)
{
  uint32_t index = tbl_hash(key) % tt->nalloc;
  llist_t* ll = tt->buckets[index];

  int i;
  for (i = 0; i < llist_size(ll); ++i)
    if (strcmp(pair_key(llist_at(ll, i)), key) == 0)
      return true;

  return false;
}
Example #4
0
void*
tbl_put(tbl_t* tt, char* key, void* value)
{
  uint32_t index = tbl_hash(key) % tt->nalloc;
  llist_t* ll = tt->buckets[index];

  bool contains = false;
  int i;
  for (i = 0; llist_size(ll); ++i) {
    if (strcmp(pair_key(llist_at(ll, i)), key) == 0) {
      contains = true;
      break;
    }
  }

  if (contains) {
    pair_t* p = ll->data[i];
    p->value = value;
  } else {
    llist_push(ll, mk_pair(key, value));
  }

  return value;
}
Example #5
0
connection_t *tbl_get(table_t *ct, __u8 client, __u8 server) {
	int index = tbl_hash(client, server);
	list_t *list = ct->map[index];

	return lst_find_con(list, client, server);
}