| 315 | unsigned long order |
| 316 | > |
| 317 | void entropy_decoder_model_kernel_4<alphabet_size,entropy_decoder,total_nodes,order>:: |
| 318 | decode ( |
| 319 | unsigned long& symbol |
| 320 | ) |
| 321 | { |
| 322 | node* temp = cur; |
| 323 | cur = 0; |
| 324 | unsigned long low_count, high_count, total_count; |
| 325 | unsigned long target; |
| 326 | node* new_node = 0; |
| 327 | |
| 328 | // local_order will track the level of temp in the tree |
| 329 | unsigned long local_order = cur_order; |
| 330 | |
| 331 | |
| 332 | while (true) |
| 333 | { |
| 334 | high_count = 0; |
| 335 | if (space_left()) |
| 336 | { |
| 337 | total_count = temp->total; |
| 338 | |
| 339 | if (total_count > 0) |
| 340 | { |
| 341 | // check if we need to scale the counts |
| 342 | if (total_count > 10000) |
| 343 | { |
| 344 | scale_counts(temp); |
| 345 | total_count = temp->total; |
| 346 | } |
| 347 | |
| 348 | target = coder.get_target(total_count); |
| 349 | |
| 350 | // find either the symbol we are looking for or the |
| 351 | // end of the context set |
| 352 | node* n = temp->child_context; |
| 353 | node* last = 0; |
| 354 | while (true) |
| 355 | { |
| 356 | high_count += n->count; |
| 357 | |
| 358 | if (high_count > target || n->next == 0) |
| 359 | break; |
| 360 | last = n; |
| 361 | n = n->next; |
| 362 | } |
| 363 | |
| 364 | low_count = high_count - n->count; |
| 365 | |
| 366 | // if we found the symbol |
| 367 | if (high_count > target) |
| 368 | { |
| 369 | if (new_node != 0) |
| 370 | { |
| 371 | new_node->parent_context = n; |
| 372 | } |
| 373 | |
| 374 | symbol = n->symbol; |