sources/middle-layer/compression/deflate/utils/huffman_table_utils.cpp
/* Init heap with the histogram, and return the histogram size */
Init heap with the histogram, and return the histogram size
Init heap with the histogram and return the histogram size
auto init_heap32(heap_tree *heap_space,
                 uint32_t * histogram,
                 uint32_t hist_size) noexcept -> uint32_t {
    uint32_t heap_size = 0;
    memset(heap_space, 0, sizeof(heap_tree));
    for (uint32_t i = 0; i < hist_size; i++) {
        if (histogram[i] != 0) {
            heap_space->heap[++heap_size] = ((static_cast<uint64_t>(histogram[i])) << FREQ_SHIFT) | i;
        }
    }
    if (heap_size < 2) {
        if (heap_size == 0) {
            heap_space->heap[1] = 1ULL << FREQ_SHIFT;
            heap_space->heap[2] = (1ULL << FREQ_SHIFT) | 1;
            heap_size = 2;
        } else {
            if (histogram[0] == 0)
                heap_space->heap[2] = 1ULL << FREQ_SHIFT;
            else
                heap_space->heap[2] = (1ULL << FREQ_SHIFT) | 1;
            heap_size = 2;
        }
    }
    build_heap(heap_space->heap, heap_size);
    return heap_size;
}
auto init_heap32 ( heap_tree * heap_space , uint32_t * histogram , uint32_t hist_size ) noexcept -> uint32_t { uint32_t heap_size = 0 ; memset ( heap_space , 0 , sizeof ( heap_tree ) ) ; for ( uint32_t i = 0 ; i < hist_size ; i ++ ) { if ( histogram [ i ] != 0 ) { heap_space -> heap [ ++ heap_size ] = ( ( static_cast < uint64_t > ( histogram [ i ] ) ) << FREQ_SHIFT ) | i ; } } if ( heap_size < 2 ) { if ( heap_size == 0 ) { heap_space -> heap [ 1 ] = 1ULL << FREQ_SHIFT ; heap_space -> heap [ 2 ] = ( 1ULL << FREQ_SHIFT ) | 1 ; heap_size = 2 ; } else { if ( histogram [ 0 ] == 0 ) heap_space -> heap [ 2 ] = 1ULL << FREQ_SHIFT ; else heap_space -> heap [ 2 ] = ( 1ULL << FREQ_SHIFT ) | 1 ; heap_size = 2 ; } } build_heap ( heap_space -> heap , heap_size ) ; return heap_size ; }
Init heap with the histogram, and return the histogram size
Init heap with the histogram and return the histogram size
// make sure heap has at least two elements in it // heap size == 1