Skip to content

Commit

Permalink
111
Browse files Browse the repository at this point in the history
  • Loading branch information
jinshaohui committed Nov 8, 2018
1 parent e53868b commit 2eb9a27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions c-cpp/19_Dlisthash/LinkedHashMap.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ int LinkedHashMap_insert(LinkedHashMap *h,void *key,void *data)

if(cur == NULL)
{
/*链表节点满时,*/
/*链表节点满时,取表头节点,从当前哈希表和双向链表中都删除*/
if(h->nel_max == h->nel)
{
cur = LinkedHashMap_delete(h,list_entry(h->header.next,LiskedHashMapNode,Dlist_node)->key);

assert(cur != NULL);
/*释放节点key 和data的内容*/
h->hash_node_free(cur,0);
}
else/*链表不满时*/
else/*链表不满时,创建新的节点*/
{
cur = (LiskedHashMapNode *)malloc(sizeof(LiskedHashMapNode));
if (cur == NULL)
Expand Down
17 changes: 9 additions & 8 deletions c-cpp/19_Dlisthash/LinkedHashMap.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
#ifndef __LINKED_HASH_MAP__
#define __LINKED_HASH_MAP__

/*数据存放节点*/
typedef struct _lisked_hash_map_node
{
void *key;
void *data;
struct _lisked_hash_map_node *next;
struct list_head Dlist_node;
void *key; /*键*/
void *data; /*数据*/ZZ
struct _lisked_hash_map_node *next; /*哈希冲突时,用来挂接后续节点*/
struct list_head Dlist_node;/*用来挂接双向链表*/
}LiskedHashMapNode;

typedef struct _lisked_hash_map
{
LiskedHashMapNode **hTabs;/*哈希桶*/
struct list_head header;/*双向循环链表头*/
int size;
int nel_max;
int nel;
int size; /**/
int nel_max; /*支持最大节点数*/
int nel; /*当前节点数*/
int (*hash_value)(struct _lisked_hash_map *h,const void *key); /*哈希函数*/
int (*keycmp)(struct _lisked_hash_map *h,const void *key1,const void *key2);/*哈希key比较函数,当哈希数值一致时使用*/
void (*hash_node_free)(LiskedHashMapNode *node,int flg);
void (*hash_node_free)(LiskedHashMapNode *node,int flg);/*用来释放节点内存*/

}LinkedHashMap;

Expand Down

0 comments on commit 2eb9a27

Please sign in to comment.