You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, no types actually use the key/value paradigm, largely because it's redundant. Let's say we want to implement a structure alike Java's HashMap<Int, String>. A simple paradigm would be
#defineLIBWHEEL_KEY int
#defineLIBWHEEL_VALUE char*
#defineLIBWHEEL_ALIAS int2string
However, this brings quite a lot of complexity with it, mostly in terms of specific macros for this specific hashtable structure. Therefore, the following alternative is proposed.
typedefstructentry {
intkey;
char*value;
}
#defineLIBWHEEL_TYPE entry
#defineLIBWHEEL_ALIAS int2string
// Use only the key field when comparing instances.int64_tcompare(entry*a, entry*b) {
returnb->key-a->key;
}
Similarly, in libwheel, we always compute the hash value whenever it is required. It is never buffered. However, a user might decide to do so themselves.
typedefstructentry {
int64_thash_value;
constchar*string;
}
// User will compute hash manually and assign it to the field.uint64_thash(entry*e) {
returne->hash_value;
}
The initialization function would then be something like
Tools
The text was updated successfully, but these errors were encountered: