Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to realize linear detection of hash table

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to realize hash table linear detection in c #, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

The HashTable- hash table / hash table is a data structure that directly accesses the memory location based on the keyword (key).

It accesses the data through a function of key values that maps the required data to the location in the table. This mapping function is called a hash function, and the array that stores records is called a hash table.

Hash conflict / hash collision

Different key values may result in the same value hash address after being processed by the hash function Hash (Key), which we call a hash conflict. Any hash function cannot avoid conflicts.

What I would like to introduce to you is the linear detection of hash table, the basic idea of linear detection:

1. Divide the length of a hash table by the length of the hash table, and put this number in the same place as the subscript of the hash table.

two。 If a hash conflict occurs, it depends on whether there is data in the next location, until there is no hash conflict, put the data in this location.

3. If the last position has been tested, but there is still a position ahead, then we will continue to explore from the starting position until all positions are tested successfully.

Implementation code:

In Hash.h

/ / the status of the data stored in the hash table enum State {EMPTY,// has no data after DELETE,// deletes data EXIST// has data} Template class HashTable {public: / / constructor HashTable (): _ table (NULL), state (NULL), _ size (0) _ capatity (0) {} / / constructor HashTable (size_t size): _ table (new K [size]), _ state (new State [size]), _ capatity (size), _ size (0) {for (int I = 0) I < _ capatity; iTunes +) {_ state [I] = EMPTY }} / / insert data bool Insert (const K & key) {/ / check whether the static hash table is full if (_ size = = _ capatity) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report