[features] Using a str=>double hashtable for feature counts
This commit is contained in:
@@ -26,18 +26,29 @@ void feature_array_add_printf(cstring_array *features, char *format, ...) {
|
||||
}
|
||||
|
||||
|
||||
bool feature_counts_update(khash_t(str_uint32) *features, char *feature, int count) {
|
||||
bool feature_counts_update_or_add(khash_t(str_double) *features, char *feature, double count, bool add) {
|
||||
khiter_t k;
|
||||
|
||||
k = kh_get(str_uint32, features, feature);
|
||||
k = kh_get(str_double, features, feature);
|
||||
if (k == kh_end(features)) {
|
||||
int ret;
|
||||
k = kh_put(str_uint32, features, feature, &ret);
|
||||
k = kh_put(str_double, features, feature, &ret);
|
||||
if (ret < 0) return false;
|
||||
|
||||
kh_value(features, k) = count;
|
||||
} else {
|
||||
} else if (add) {
|
||||
kh_value(features, k) += count;
|
||||
} else {
|
||||
kh_value(features, k) = count;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool feature_counts_add(khash_t(str_double) *features, char *feature, double count) {
|
||||
return feature_counts_update_or_add(features, feature, count, true);
|
||||
}
|
||||
|
||||
inline bool feature_counts_update(khash_t(str_double) *features, char *feature, double count) {
|
||||
return feature_counts_update_or_add(features, feature, count, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user