1321936Shselasky/* 2321936Shselasky * Copyright (c) 2017 Mellanox Technologies LTD. All rights reserved. 3321936Shselasky * 4321936Shselasky * This software is available to you under a choice of one of two 5321936Shselasky * licenses. You may choose to be licensed under the terms of the GNU 6321936Shselasky * General Public License (GPL) Version 2, available from the file 7321936Shselasky * COPYING in the main directory of this source tree, or the 8321936Shselasky * OpenIB.org BSD license below: 9321936Shselasky * 10321936Shselasky * Redistribution and use in source and binary forms, with or 11321936Shselasky * without modification, are permitted provided that the following 12321936Shselasky * conditions are met: 13321936Shselasky * 14321936Shselasky * - Redistributions of source code must retain the above 15321936Shselasky * copyright notice, this list of conditions and the following 16321936Shselasky * disclaimer. 17321936Shselasky * 18321936Shselasky * - Redistributions in binary form must reproduce the above 19321936Shselasky * copyright notice, this list of conditions and the following 20321936Shselasky * disclaimer in the documentation and/or other materials 21321936Shselasky * provided with the distribution. 22321936Shselasky * 23321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30321936Shselasky * SOFTWARE. 31321936Shselasky * 32321936Shselasky */ 33321936Shselasky 34329566Shselasky#if __cplusplus >= 201103L 35321936Shselasky#include <unordered_map> 36329566Shselasky#define UM_NAMESPACE std 37325935Shselasky#else 38325935Shselasky#include <tr1/unordered_map> 39329566Shselasky#define UM_NAMESPACE std::tr1 40325935Shselasky#endif 41321936Shselasky 42321936Shselaskyclass HashTable { 43321936Shselaskypublic: 44329566Shselasky UM_NAMESPACE::unordered_map<void *, void *> map; 45321936Shselasky HashTable() { }; 46321936Shselasky ~HashTable() { }; 47321936Shselasky}; 48321936Shselasky 49321936Shselaskyextern "C" { 50321936Shselasky 51321936Shselasky#if HAVE_CONFIG_H 52321936Shselasky#include <config.h> 53321936Shselasky#endif 54321936Shselasky 55321936Shselasky#include "internal.h" 56321936Shselasky 57321936ShselaskyGHashTable * 58321936ShselaskyGHashTableNew(void) 59321936Shselasky{ 60321936Shselasky return ((GHashTable *)(new HashTable())); 61321936Shselasky} 62321936Shselasky 63321936Shselaskyvoid 64321936ShselaskyGHashTableDestroy(GHashTable *ght) 65321936Shselasky{ 66321936Shselasky delete (HashTable *)ght; 67321936Shselasky} 68321936Shselasky 69321936Shselaskyvoid 70321936ShselaskyGHashTableInsert(GHashTable *ght, void *key, void *value) 71321936Shselasky{ 72321936Shselasky HashTable *ht = (HashTable *)ght; 73321936Shselasky ht->map[key] = value; 74321936Shselasky} 75321936Shselasky 76321936Shselaskyvoid * 77321936ShselaskyGHashTableLookup(GHashTable *ght, void *key) 78321936Shselasky{ 79321936Shselasky HashTable *ht = (HashTable *)ght; 80321936Shselasky 81321936Shselasky if (ht->map.find(key) == ht->map.end()) 82321936Shselasky return (NULL); 83321936Shselasky return (ht->map[key]); 84321936Shselasky} 85321936Shselasky 86321936Shselasky} 87