| 93 | } |
| 94 | |
| 95 | I32 ArithmeticModel::init(U32* table) |
| 96 | { |
| 97 | if (distribution == 0) |
| 98 | { |
| 99 | if ( (symbols < 2) || (symbols > (1 << 11)) ) |
| 100 | { |
| 101 | return -1; // invalid number of symbols |
| 102 | } |
| 103 | last_symbol = symbols - 1; |
| 104 | if ((!compress) && (symbols > 16)) |
| 105 | { |
| 106 | U32 table_bits = 3; |
| 107 | while (symbols > (1U << (table_bits + 2))) ++table_bits; |
| 108 | table_size = 1 << table_bits; |
| 109 | table_shift = DM__LengthShift - table_bits; |
| 110 | distribution = new U32[2*symbols+table_size+2]; |
| 111 | decoder_table = distribution + 2 * symbols; |
| 112 | } |
| 113 | else // small alphabet: no table needed |
| 114 | { |
| 115 | decoder_table = 0; |
| 116 | table_size = table_shift = 0; |
| 117 | distribution = new U32[2*symbols]; |
| 118 | } |
| 119 | if (distribution == 0) |
| 120 | { |
| 121 | return -1; // "cannot allocate model memory"); |
| 122 | } |
| 123 | symbol_count = distribution + symbols; |
| 124 | } |
| 125 | |
| 126 | total_count = 0; |
| 127 | update_cycle = symbols; |
| 128 | if (table) |
| 129 | for (U32 k = 0; k < symbols; k++) symbol_count[k] = table[k]; |
| 130 | else |
| 131 | for (U32 k = 0; k < symbols; k++) symbol_count[k] = 1; |
| 132 | |
| 133 | update(); |
| 134 | symbols_until_update = update_cycle = (symbols + 6) >> 1; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | void ArithmeticModel::update() |
| 140 | { |
nothing calls this directly
no outgoing calls
no test coverage detected