The function h (key) used in the hash store is called a hash function or hash function, which implements the mapping (or conversion) of the keyword to the storage address.
It's not easy to delete or insert.
Find the most convenient O (1)
C + + implementation Hash List lookup
1#include"Hash.h"2#include"Hashnode.h"3 4template<classT>5 intHash<t>::myhash (intKey//Seeking Redundancy6 {7 returnkey%N;8 }9 Tentemplate<classT> One voidHash<t>::init (T *pt,intnt//Initialize A { - for(inti =0; I <Ten; i++) - { theP[i].key =i; -p[i].t =Pt[i]; -p[i].cn =0; - } + } - +template<classT> A BOOLHash<t>::isin (intKey, T T)//whether there is at { - intres =Myhash (key); - if(p[res].t = =t) - { - return true; - } in Else - { to return false; + } - } the *template<classT> $Hashnode<t> *hash<t>::find (intKey//FindPanax Notoginseng { - intres =Myhash (key); the returnP +Res; + } A thetemplate<classT> +Hash<t>::hash ()//constructor Function - { $ This->n =Ten; $ This->p =Newhashnode<t>[ This-n]; - } - thetemplate<classT> -Hash<t>::~hash ()// DestructorsWuyi { the Delete[]p; -}
8.4 Hash List Lookup