summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--st.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/st.c b/st.c
index 1401ba0180..5fa7e24f53 100644
--- a/st.c
+++ b/st.c
@@ -416,6 +416,46 @@ st_insert(register st_table *table, register st_data_t key, st_data_t value)
}
}
+int
+st_insert2(register st_table *table, register st_data_t key, st_data_t value,
+ st_data_t (*func)(st_data_t))
+{
+ unsigned int hash_val, bin_pos;
+ register st_table_entry *ptr;
+
+ if (table->entries_packed) {
+ st_index_t i;
+ for (i = 0; i < table->num_entries; i++) {
+ if ((st_data_t)table->bins[i*2] == key) {
+ table->bins[i*2+1] = (struct st_table_entry*)value;
+ return 1;
+ }
+ }
+ if ((table->num_entries+1) * 2 <= table->num_bins && table->num_entries+1 <= MAX_PACKED_NUMHASH) {
+ i = table->num_entries++;
+ table->bins[i*2] = (struct st_table_entry*)key;
+ table->bins[i*2+1] = (struct st_table_entry*)value;
+ return 0;
+ }
+ else {
+ unpack_entries(table);
+ }
+ }
+
+ hash_val = do_hash(key, table);
+ FIND_ENTRY(table, ptr, hash_val, bin_pos);
+
+ if (ptr == 0) {
+ key = (*func)(key);
+ ADD_DIRECT(table, key, value, hash_val, bin_pos);
+ return 0;
+ }
+ else {
+ ptr->record = value;
+ return 1;
+ }
+}
+
void
st_add_direct(st_table *table, st_data_t key, st_data_t value)
{