8.4 Hash List Lookup

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.