hashtable...squid

S

s88

I work with the bit-vector(http://search.cpan.org/dist/Bit-Vector/)
and squid lib as well. But I meet a weird situation now...Let's see my
code.
I wanna creat a hashtable in a function, and then return the address of
the hashtable.
But my hashtable looks empty outside the fake_table().
The hashtable just manage the pointer I insert. Don't really "copy"
anything into the table.


hashtable *fake_table(){

BitVector_Boot();
N_char x1[] = "101000";
N_char x2[] = "101010";

wordptr X1 = BitVector_Create(6, 1);
wordptr X2 = BitVector_Create(6, 1);

BitVector_from_Bin(X1, x1);
BitVector_from_Bin(X2, x2);

hash_table *inst_table =
hash_create(inst_tb_compare,7951,hash_string);
hash_table *ht2 =
hash_create(inst_tb_compare,7951,hash_string);

inst_tb_atom *_atom1 = (inst_tb_atom
*)malloc(sizeof(inst_tb_atom));
inst_tb_atom *_atom2 = (inst_tb_atom
*)malloc(sizeof(inst_tb_atom));

_atom1->_type = 1;
_atom1->point_to.ht = ht2;
_atom1->X = X1;

_atom2->_type = 1;
_atom2->point_to.ht = ht3;
_atom2->X = X2;

hash_insert(ht2,x2,_atom2);
hash_insert(inst_table,x1,_atom1);

return inst_table;
}

Thanx!!!
 
J

Jack Klein

I work with the bit-vector(http://search.cpan.org/dist/Bit-Vector/)
and squid lib as well. But I meet a weird situation now...Let's see my
code.
I wanna creat a hashtable in a function, and then return the address of
the hashtable.
But my hashtable looks empty outside the fake_table().
The hashtable just manage the pointer I insert. Don't really "copy"
anything into the table.

The problem here is that your code is littered with non-standard types
that are apparently defined (with typedef or macros) in the header
files for the third party libraries that you are trying to use.
hashtable *fake_table(){

BitVector_Boot();

The C language does not define what this function call does, so there
is no reason at all to assume that anyone here knows either.
N_char x1[] = "101000";
N_char x2[] = "101010";

Here you appear to be defining two arrays of type 'N_char', which must
be an alias for one of the character types, after calling a function.
Does your compiler conform to the 1999 or later version of the C
standard? This is illegal code in earlier versions of C.

wordptr X1 = BitVector_Create(6, 1);
wordptr X2 = BitVector_Create(6, 1);

BitVector_from_Bin(X1, x1);
BitVector_from_Bin(X2, x2);

hash_table *inst_table =
hash_create(inst_tb_compare,7951,hash_string);
hash_table *ht2 =
hash_create(inst_tb_compare,7951,hash_string);

inst_tb_atom *_atom1 = (inst_tb_atom
*)malloc(sizeof(inst_tb_atom));

Casting the pointer returned by malloc() in C is unnecessary and can
hide a serious error causing undefined behavior if <stdlib.h> is not
included or there is otherwise not a proper prototype for malloc() in
scope.

Also you are committing the serious error of not checking the return
value of malloc() for NULL, which it will return if the allocation
fails.

inst_tb_atom *_atom2 = (inst_tb_atom
*)malloc(sizeof(inst_tb_atom));

_atom1->_type = 1;
_atom1->point_to.ht = ht2;
_atom1->X = X1;

_atom2->_type = 1;
_atom2->point_to.ht = ht3;
_atom2->X = X2;

hash_insert(ht2,x2,_atom2);
hash_insert(inst_table,x1,_atom1);

return inst_table;
}

Thanx!!!

We haven't got the faintest idea of how these functions get the memory
they use. You'll have to talk to whoever made the library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top