コード例 #1
0
ファイル: Hash-test.c プロジェクト: rlowrance/re
static void testFree()
{
  Hash_T h0 = Hash_new(0);
  Hash_free(&h0);
  EXPECT_NULL(h0);

  Hash_T h1 = Hash_new(1);
  Hash_free(&h1);
  EXPECT_NULL(h1);

  Hash_T h2 = Hash_new(2);
  Hash_free(&h2);
  EXPECT_NULL(h2);
}
コード例 #2
0
ファイル: hash.c プロジェクト: QubeX2/mangolib
Hash_T Hash_load(const char *file) {
    int fd, read, done = 0, i;
    int d[2];
    Hash_T h = NULL;

    if((fd=File_openRead(file)) != -1) {
        h = Hash_new();
        while(!done) {
            for(i=0; i<2; i++) {
                read = File_read(fd, &d[i], sizeof(int));
                if(read == -1)
                    goto err;
                else if(read == 0)
                    done = 1;
                else
                    Hash_add(h, d[0], d[1]);
            }
        }
    }
    return h;

err:
    Hash_free(&h);
    return Hash_new();
}
コード例 #3
0
ファイル: Hash-test.c プロジェクト: rlowrance/re
static void testInsert()
{
  // test general case
  Hash_T h0 = Hash_new(0);
  EXPECT_EQ_UINT32(0, h0->nElements);
  EXPECT_EQ_UINT32(0, h0->tableSize);

  int key1 = 123;
  char* value1 = "1";
  h0 = Hash_insert(h0, Atom_newFromInt64(key1), value1);
  EXPECT_NOT_NULL(h0);
  EXPECT_EQ_UINT32(1, h0->nElements);
  EXPECT_EQ_UINT32(1, h0->tableSize);

  int key2 = -27;
  char value2[] = "value2";
  h0 = Hash_insert(h0, Atom_newFromInt64(key2), value2);
  EXPECT_NOT_NULL(h0);
  EXPECT_EQ_UINT32(2, h0->nElements);
  EXPECT_EQ_UINT32(3, h0->tableSize);

  char * key3 = "abc";
  int16_t value3 = 1056;
  Str_T s = Str_newFromInt16(value3);
  h0 = Hash_insert(h0, Atom_newFromString(key3), Str_str(s));
  EXPECT_NOT_NULL(h0);
  EXPECT_EQ_UINT32(3, h0->nElements);
  EXPECT_EQ_UINT32(3, h0->tableSize);
  Str_free(&s);

  Hash_free(&h0);
  EXPECT_NULL(h0);
}