Added vp8_update_zbin_extra
[libvpx.git] / vpx_mem / memory_manager / hmm_largest.c
blobc3c6f2c422cb7e00f4c9a81b05c8748774fbde15
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 /* This code is in the public domain.
13 ** Version: 1.1 Author: Walt Karas
16 #include "hmm_intrnl.h"
18 U(size_aau) U(largest_available)(U(descriptor) *desc)
20 U(size_bau) largest;
22 if (!(desc->avl_tree_root))
23 largest = 0;
24 else
26 #ifdef HMM_AUDIT_FAIL
27 /* Audit root block in AVL tree. */
28 AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
29 #endif
31 largest =
32 BLOCK_BAUS(
33 PTR_REC_TO_HEAD(
34 U(avl_search)(
35 (U(avl_avl) *) & (desc->avl_tree_root),
36 (U(size_bau)) ~(U(size_bau)) 0, AVL_LESS)));
39 if (desc->last_freed)
41 /* Size of last freed block. */
42 register U(size_bau) lf_size;
44 #ifdef HMM_AUDIT_FAIL
45 AUDIT_BLOCK(desc->last_freed)
46 #endif
48 lf_size = BLOCK_BAUS(desc->last_freed);
50 if (lf_size > largest)
51 largest = lf_size;
54 /* Convert largest size to AAUs and subract head size leaving payload
55 ** size.
57 return(largest ?
58 ((largest * ((U(size_aau)) HMM_BLOCK_ALIGN_UNIT)) - HEAD_AAUS) :
59 0);