struct HXmap_trav *trav = HXmap_travinit(AssetMap);
        struct HXmap_node *nodeptr = HXmap_traverse(HXmap_trav);
        printf("KEY %s DATA: %p\n",HXmap_node->skey,HXmap_node->data);

How do I traverse a map? Is there any sample code, which can tell me how to iterate through the map. I didnt understand HXmap_qfe properly.


On 17 February 2011 02:01, Jan Engelhardt <> wrote:

On Wednesday 2011-02-16 21:06, Soham Das wrote:
>int main()
>    HXmap* AssetMap =  HXmap_init5(HXMAPT_DEFAULT,HXMAP_CKEY,NULL,256,0);
>    Message* newMessage= (Message*)malloc(sizeof(Message));

(Casting the result of malloc is not required, neither is from
HXmap_get or other functions returning void*.)

>    parser("N,8545,01/02/2011 09:15:01.815,\"RASTA OPTSTK 24FEB2011 1,150.00
>    printf("AssetName: %s\n",newMessage->asset);

You did not post the definition of Message, but from your use of %s,
I suspect that newMessage->asset is a char* (or char[]), i.e.
pointing to a C string. Since such strings can be of dynamic length,
specifying 256 is (most likely) wrong. If "N,8545,...0.00,0" is the
string pointed to by newMessage->asset, then using 256 would copy
bytes from beyond the end of the string, which is undefined behavior.

To use strings as keys, use

       /* or simply */


>    case 'N':
>            newOrder=Order_Init(newMessage->idNum,newMessage->BS,newMessage->shares1,newMessage
>->price1,newMessage->Time,NULL);//create a new order;
>            asset = HXmap_get(AssetMap,&newMessage->asset);        //does

since newMessage->asset is already of type char* and does already
point to the key, using &newMessage->asset would give you char**, and
a pointer to the "asset" member itself, rather than a pointer to the
key. The same then also holds for:

>              HXmap_add(AssetMap,&newMessage->asset,asset);   
>                Check = HXmap_get(AssetMap,&newMessage->asset);
>    Check =(Asset*) HXmap_get(AssetMap,&newMessage->asset);

In other words, it should just be HXmap_get(AssetMap, newMessage->asset);