def tbb_chm_at(chm, key, hasher=None): h = hash_of(key, hasher) & tbb_atomic_get(chm['my_mask']) # This simulates an Intel BSR (i.e., lg2) on h|1. s = len('{0:b}'.format(int(h | 1))) - 1 # segment_idx h -= 1 << s & ~1 # segment_base # bucket_accessor b(this, h & m) <=> this->get_bucket(h & m). seg = chm['my_table'][s] b = seg[h].address if b['node_list'] == V('tbb::interface5::internal::rehash_req'): # Rehash required, so just give up. return None node_ptype = T(str(rawtype(chm.type)) + '::node').pointer() node = b['node_list'].cast(node_ptype) # search_bucket(key, b). while node.cast(T('size_t')) > 63 and key != node['item']['first']: node = node['next'].cast(node_ptype) if node == nullptr(): return None return node['item']['second']
def tbb_chm_at(chm, key): h = hash_of(key) & tbb_atomic_get(chm["my_mask"]) # This simulates an Intel BSR (i.e., lg2) on h|1. s = len("{0:b}".format(int(h | 1))) - 1 # segment_idx h -= 1 << s & ~1 # segment_base # bucket_accessor b(this, h & m) <=> this->get_bucket(h & m). seg = chm["my_table"][s] b = seg[h].address if b["node_list"] == V("tbb::interface5::internal::rehash_req"): # Rehash required, so just give up. return None node_ptype = T(str(rawtype(chm.type)) + "::node").pointer() node = b["node_list"].cast(node_ptype) # search_bucket(key, b). while node.cast(T("size_t")) > 63 and key != node["item"]["first"]: node = node["next"].cast(node_ptype) if node == nullptr(): return None return node["item"]["second"]
def tread_hash_map_at(thm, key, hasher=None): table = atomic_get(thm['m_table']) capac = table['capac'] idx = (hash_of(key, hasher) & (capac - 1)).cast(T('size_t')) while True: entry = table['entries'][idx] probe = atomic_get(entry['first']) if probe == key: return entry['second'] if probe == 0: return None idx += 1 if idx == capac: idx = 0
def tread_hash_map_at(thm, key): table = atomic_get(thm["m_table"]) capac = table["capac"] idx = (hash_of(key) & (capac - 1)).cast(T("size_t")) while True: entry = table["entries"][idx] probe = atomic_get(entry["first"]) if probe == key: return entry["second"] if probe == 0: return None idx += 1 if idx == capac: idx = 0
def unordered_map_at(umap, key, hasher=None): h = umap['_M_h'] bucket = h['_M_buckets'][hash_of(key, hasher) % h['_M_bucket_count']] if bucket == 0x0: return None node = bucket['_M_nxt'] value_type = T(str(rawtype(umap.type)) + '::value_type').pointer() while node != 0x0: # Hashtable nodes contain only a pointer to the next node in the # bucket, but are always immediately followed by the value pair. value = (node + 1).cast(value_type) if key == value['first']: return value['second'] node = node['_M_nxt'] return None
def unordered_map_at(umap, key): h = umap["_M_h"] bucket = h["_M_buckets"][hash_of(key) % h["_M_bucket_count"]] if bucket == 0x0: return None node = bucket["_M_nxt"] value_type = T(str(umap.type) + "::value_type").pointer() while node != 0x0: # Hashtable nodes contain only a pointer to the next node in the # bucket, but are always immediately followed by the value pair. value = (node + 1).cast(value_type) if key == value["first"]: return value["second"] node = node["_M_nxt"] return None