最近、リストやマップなどのGLibのタイプを使用していますが、面倒な問題が発生しました。GLib:値を正しく見つけることができないハッシュテーブル
BoneIdMap = g_hash_table_new(g_direct_hash, g_str_equal);
私は、文字列のキーにいくつかのUINTを挿入し、それを試してみると、それは完璧に動作します:
char* string = alloq_calloc(&model->dynamic, strlen(aimesh->mBones[x]->mName.data) + 1, sizeof(char));
strcpy(string, aimesh->mBones[x]->mName.
if(map_find(&model->BoneIdMap, string, &handle)) {
index = *handle;
} else {
index = model->BoneIdMap.size;
}
map_insert(&model->BoneIdMap, &index, sizeof(uint), string);
注意し
オフから、私のような私のハッシュテーブルを作成しました:私は静的配列を渡してみたので、ポインタが動的に割り振られているので、動作しません。(両方とも動作しないことが分かります)
その後、これらの単位を後で試してみますラインWN:
char* string = alloq_calloc(&model->dynamic, strlen(ainode->mName.data) + 1, sizeof(char));
strcpy(string, ainode->mName.data);
/* Time to do some debugging */
if(map_find(&model->BoneIdMap, string, &handle)) {
しかし、それは単に動作しませんが...私は配列にすべてのキーを取得しようとした:
uint len;
char** arr = g_hash_table_get_keys_as_array(model->BoneIdMap.table, &len);
for(int i = 0; i < len; ++i) {
if(arr[i]) printf("Key: %s\n", arr[i]);
if(!strcmp(arr[i], ainode->mName.data)) printf("Yes!\n");
}
printf("----------------------------\n");
をし、それが動作します!!! (???)
Key: pelvis
Key: toe.L
Yes!
Key: sheath
Key: lamp
----------------------------
Key: toe.R
Key: shin.L
Key: fingerstip.R
Key: neck
Key: thigh.R
Key: fingers.L
Key: shin.R
Key: spine
Key: lamp
Key: head
Key: fingerstip.L
Key: thm_end.L
Key: thm_end.R
Key: tiptoe.L
Yes!
Key: upperarm.R
は、私は上記の印刷機能以外にもすぐそこに静的な文字列を使用してキーを追加し、それを見つけようとした場合、それがうまくいくことに注意してください!あなたはg_direct_hash
ハッシュ関数を使用している
Public Attributes
char data [MAXLEN]
String buffer.
size_t length
Binary length of the string excluding the terminal 0.
をお読みいただきありがとうございました...
あなたの 'map_insert'と' map_find'コードは、両方ともGLibハッシュテーブル関数に関するラッパー関数であると仮定しているので、それらを共有してください。 – tgregory