prg_bin_hash_table_item_insert()

Abstract

Inserts a new value into a hash table.

Syntax

prg_bin_hash_table_item_insert (hash_ptr, key, value_ptr, old_value_pptr)
Argument Type Description
hash_ptr PrgT_Bin_Hash_Table * Hash table of interest.
key const void * Key associated with the value to be inserted into the table.
value_ptr void * Value to be inserted into the table.
old_value_pptr void ** Area to hold a pointer to the previous value for key, if any; PRGC_NIL otherwise.

Return Type

void

No return value.

prg_bin_hash.h

Details

This function uses key to determine the location at which to insert value_ptr. If the hash table already contains a value for this key, the previous pointer is placed in old_value_pptr and removed from the hash table.

To guard against cases of duplicate keys, your code should check to see if old_value_pptr is PRGC_NIL. If not, the key was used previously and you must save the previous value somehow. One way is to use the chaining method, in which the hash table entry for duplicate keys is a list of values. To use the chaining method:

  1. Combine the cell’s previous value (from old_value_pptr) and the new value (value_ptr) in a list.
  2. Call prg_bin_hash_table_item_insert() again to store this new list of values at the key position.

WARNING: This function is MT unsafe, as described in “Multi-Threading Safety“ on page 11. Access to shared hash tables must be externally serialized.

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com