/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
staticint accounting_hash(constchar *str) {
uint32_t val; constunsignedchar *ustr;
val = 0;
ustr = (constunsignedchar *)str; /* This is about the worst hash one can design, but it should be good enough
here. */ while (*ustr) val += *ustr++; return val % AOM_ACCOUNTING_HASH_SIZE;
}
/* Dictionary lookup based on an open-addressing hash table. */ int aom_accounting_dictionary_lookup(Accounting *accounting, constchar *str) { int hash;
size_t len;
AccountingDictionary *dictionary;
dictionary = &accounting->syms.dictionary;
hash = accounting_hash(str); while (accounting->hash_dictionary[hash] != -1) { if (strcmp(dictionary->strs[accounting->hash_dictionary[hash]], str) == 0) { return accounting->hash_dictionary[hash];
}
hash++; if (hash == AOM_ACCOUNTING_HASH_SIZE) hash = 0;
} /* No match found. */
assert(dictionary->num_strs + 1 < MAX_SYMBOL_TYPES);
accounting->hash_dictionary[hash] = dictionary->num_strs;
len = strlen(str);
dictionary->strs[dictionary->num_strs] = malloc(len + 1); if (!dictionary->strs[dictionary->num_strs]) abort();
snprintf(dictionary->strs[dictionary->num_strs], len + 1, "%s", str);
dictionary->num_strs++; return dictionary->num_strs - 1;
}
void aom_accounting_init(Accounting *accounting) { int i;
accounting->num_syms_allocated = 1000;
accounting->syms.syms =
malloc(sizeof(AccountingSymbol) * accounting->num_syms_allocated); if (!accounting->syms.syms) abort();
accounting->syms.dictionary.num_strs = 0;
assert(AOM_ACCOUNTING_HASH_SIZE > 2 * MAX_SYMBOL_TYPES); for (i = 0; i < AOM_ACCOUNTING_HASH_SIZE; i++)
accounting->hash_dictionary[i] = -1;
aom_accounting_reset(accounting);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.