[instancer/varstore] Use heapify() instead of inserts()

This commit is contained in:
Behdad Esfahbod committed 2025-09-12 00:52:40 -06:00
1 parent 12c4623757
commit aba798ddab
2 files changed
+19 -3

No files matched your search

+8 -2
View File
@@ -1894,7 +1894,8 @@ struct item_variations_t
/* main algorithm: repeatedly pick 2 best encodings to combine, and combine
* them */
hb_priority_queue_t<combined_gain_idx_tuple_t> queue;
using item_t = hb_priority_queue_t<combined_gain_idx_tuple_t>::item_t;
hb_vector_t<item_t> queue_items;
unsigned num_todos = encoding_objs.length;
for (unsigned i = 0; i < num_todos; i++)
{
@@ -1902,10 +1903,15 @@ struct item_variations_t
{
int combining_gain = encoding_objs.arrayZ[i].gain_from_merging (encoding_objs.arrayZ[j], scratch);
if (combining_gain > 0)
queue.insert (combined_gain_idx_tuple_t (-combining_gain, i, j), 0);
{
auto item = item_t (combined_gain_idx_tuple_t (-combining_gain, i, j), 0);
queue_items.push (item);
}
}
}
hb_priority_queue_t<combined_gain_idx_tuple_t> queue (std::move (queue_items));
hb_bit_set_t removed_todo_idxes;
while (queue)
{
+11 -1
View File
@@ -45,12 +45,22 @@
template <typename K>
struct hb_priority_queue_t
{
private:
public:
typedef hb_pair_t<K, unsigned> item_t;
private:
hb_vector_t<item_t> heap;
public:
hb_priority_queue_t () = default;
hb_priority_queue_t (hb_vector_t<item_t>&& other) : heap (std::move (other))
{
// Heapify the vector.
for (int i = (heap.length / 2) - 1; i >= 0; i--)
bubble_down (i);
}
void reset () { heap.resize (0); }
bool in_error () const { return heap.in_error (); }