diff options
| author | chenzizhan <[email protected]> | 2024-03-18 18:06:08 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2024-03-18 18:06:08 +0800 |
| commit | 066f118246d476a6d229fd28bd8702dcc17d6a13 (patch) | |
| tree | 23fbacac67edcde0ee7b046d4aa3369f96d2ec1c | |
| parent | 41c6d57578e9ed71b3ce9f821c99def8ac3c5499 (diff) | |
assert on dangling tag pointer
| -rw-r--r-- | src/tags/heavy_keeper.c | 12 | ||||
| -rw-r--r-- | src/tags/sorted_set.c | 16 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/tags/heavy_keeper.c b/src/tags/heavy_keeper.c index 8c86d06..24b33fc 100644 --- a/src/tags/heavy_keeper.c +++ b/src/tags/heavy_keeper.c @@ -183,6 +183,9 @@ static int heavy_keeper_add_by_recording_popped_data(struct heavy_keeper *heavy_ assert(cell_id >= 0); assert(tag != NULL); + long long tmp_v = tag->hashv; + assert(tmp_v >= 0); + if (sorted_set_cardinality(heavy_keeper->top_K_heap) < heavy_keeper->K) { sorted_set_insert_and_record_popped_back(heavy_keeper->top_K_heap, tag, 0, cell_id, popped_id_out); return 0; // newly added @@ -230,6 +233,9 @@ static int heavy_keeper_add_by_recording_popped_data(struct heavy_keeper *heavy_ if ((maxv - nMin <= count && maxv != nMin) || sorted_set_cardinality(summary) != heavy_keeper->K) { assert(cell_id >= 0); assert(tag != NULL); + long long tmp_v = tag->hashv; + assert(tmp_v >= 0); + int insert_ret = sorted_set_insert_and_record_popped_back(summary, tag, maxv, cell_id, &user_data_cube_id); if (insert_ret == 2) { // insert success and popped one *popped_id_out = user_data_cube_id; @@ -419,7 +425,8 @@ void heavy_keeper_merge_sorted_set_recording_id_details(struct heavy_keeper *des int max_size = size_dest > size_src ? size_dest : size_src; unsigned *count_arr = (unsigned *)malloc(max_size * sizeof(unsigned)); - struct tag_hash_key **tag_arr = (struct tag_hash_key **)malloc(max_size * sizeof(struct tag_hash_key *)); + // struct tag_hash_key **tag_arr = (struct tag_hash_key **)malloc(max_size * sizeof(struct tag_hash_key *)); + struct tag_hash_key **tag_arr = (struct tag_hash_key **)calloc(max_size, sizeof(struct tag_hash_key *)); int *cell_id_arr_dst = (int *)malloc(size_dest * sizeof(int)); sorted_set_dump(ss_dest, count_arr, tag_arr, cell_id_arr_dst); @@ -440,7 +447,8 @@ void heavy_keeper_merge_sorted_set_recording_id_details(struct heavy_keeper *des qsort(cell_id_arr_dst, size_dest, sizeof(int), cmp_int); // use in find_next_unused_cell_id to find the minimum unused cell_id /* ------------------------------ merge source ------------------------------ */ - int *cell_id_arr_src = (int *)malloc(size_src * sizeof(int)); + // int *cell_id_arr_src = (int *)malloc(size_src * sizeof(int)); + int *cell_id_arr_src = (int*)calloc(size_src, sizeof(int)); sorted_set_dump(ss_src, count_arr, tag_arr, cell_id_arr_src); int last_find_id = -1; int next_idx = 0; diff --git a/src/tags/sorted_set.c b/src/tags/sorted_set.c index febd405..2f9dd7a 100644 --- a/src/tags/sorted_set.c +++ b/src/tags/sorted_set.c @@ -39,6 +39,9 @@ struct entry_data *entry_data_construct(const struct tag_hash_key *tag, int cell {
assert(cell_id >= 0);
assert(tag != NULL);
+ long long tmp_v = tag->hashv;
+ assert(tmp_v >= 0);
+
struct entry_data *entry_data = (struct entry_data *)malloc(sizeof(struct entry_data));
entry_data->key = tag_hash_key_copy(tag);
@@ -71,6 +74,9 @@ struct entry_data *sorted_set_entry_get_data(const heap_entry *entry) const struct entry_data * tmp_val = (struct entry_data *)entry->value;
assert(tmp_val->key != NULL);
+ long long tmp_v = tmp_val->key->hashv;
+ assert(tmp_v >= 0);
+
assert(tmp_val->cell_id >= 0);
return entry->value;
}
@@ -230,6 +236,9 @@ int sorted_set_insert(struct sorted_set *ss, const struct tag_hash_key *tag, uns {
assert(cell_id >= 0);
assert(tag != NULL);
+ long long tmp_v = tag->hashv;
+ assert(tmp_v >= 0);
+
if (sorted_set_check_is_full(ss)) {
if (cnt <= sorted_set_get_min_count(ss)) {
return 0;
@@ -244,6 +253,9 @@ int sorted_set_insert_and_record_popped_back(struct sorted_set *ss, const struct {
assert(cell_id >= 0);
assert(tag != NULL);
+ long long tmp_v = tag->hashv;
+ assert(tmp_v >= 0);
+
// if there is a dying record, reborn it to use.
heap_entry *entry = sorted_set_find_entry(ss, tag);
if (entry != NULL) {
@@ -365,11 +377,15 @@ void sorted_set_dump(const struct sorted_set *ss, unsigned *scores_out, struct t tmp_nodes[n_living_entry].val = sorted_set_entry_get_data(entry);
n_living_entry++;
}
+ assert(n_living_entry == ss->n_living_entry);
qsort(tmp_nodes, n_living_entry, sizeof(tmp_heap_node), cmp_tmp_heap_node);
for (int i = 0; i < n_living_entry; i++) {
assert(tmp_nodes[i].val != NULL);
assert(tmp_nodes[i].val->cell_id >= 0);
assert(tmp_nodes[i].val->key != NULL);
+ long long tmp_haha = tmp_nodes[i].val->key->hashv;
+ assert(tmp_haha >= 0);
+
scores_out[i] = tmp_nodes[i].key;
tags_out[i] = tmp_nodes[i].val->key;
user_data_out[i] = tmp_nodes[i].val->cell_id;
|
