/* * ia_11.4openaddressing.cpp * * Created on:feb, * author:sunyj * * * #include <stdint.h> #include < String.h> #include <iostream>class Node {public:node () {} node (int64_t const K, int64_t const D): Key (k), Data (d) {} int64_t key; int64_t data;}; Class Openaddressinglinerprob {public:openaddressinglinerprob (int64_t const N): Length (n) {data = new Node N (); memset (data,-1, n * sizeof (Node)); } int64_t Hashfunc (int64_t const key) {return key% length; } Node Hashfunclinerprobsearch (int64_t const key) {for (int64_t i = 0; i < length; i++) { if (Data[hashfunc (key) + I].key = = key) {return Data[hashfunc (key) + i]; }} return Node (); } void Hashfunclinerprobinsert (Node const x) {for (int64_t i = 0; i < length; i++) {if (Data[hashfunc (x.key) + I].key = =-1) { Data[hashfunc (X.key) + i] = x; return; }}}private:node* data; int64_t length;}; int main () {Openaddressinglinerprob linertable (7); Node Node2 (2, 200); Node Node3 (5, 300); Node Node9 (9, 900); Node Node4 (4, 400); Linertable. Hashfunclinerprobinsert (Node2); Linertable. Hashfunclinerprobinsert (NODE3); Linertable. Hashfunclinerprobinsert (NODE9); Linertable. Hashfunclinerprobinsert (NODE4); Node tmp = linertable. Hashfunclinerprobsearch (4); Std::cout << tmp.data << Std::endl; TMP = linertable. Hashfunclinerprobsearch (2); Std::cout << tmp.data << Std::endl; TMP = linertable. Hashfunclinerprobsearch (9); Std::cout << tmp.data << Std::endl; return 0;} Linear probing
Introduction to the algorithm 11.4 open addressing method (except Fahahi function open addressing handling conflict)