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

How to implement Hash algorithm based on Python

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

Share

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

This article mainly explains "how to implement Hash algorithm based on Python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "How to implement Hash algorithm based on Python"!

1 Introduction

Simhash's algorithm is simple, from a large number of texts quickly search and known simhash difference less than k simhash set, where each text can be represented by a simhash value, a simhash has 64 bits, similar text, 64 bits are also similar, the empirical value of k in the paper is 3. The disadvantages of this method are as obvious as the advantages. There are two main points: for short text, k value is very sensitive; the other is that the algorithm trades space for time, and the system memory is too much.

2 General hash algorithm

The simplest hash algorithm is to store data according to the hash address in the residual way, which requires providing a key-value pair (Key is the address, value is the stored data).

2.1 algorithm logic

Input stored data and create (Key-value) objects

By taking the remainder formula H = d H=d%nH=d H: hash address, d is data, unique, n is total number of samples

Store the generated hash address and corresponding data into a dictionary object

2.2 Code implementation # 1. Data records to be recorded = [[1,50],[2,6],[3,47],[4,9],[6,100]] #Data key is date, value is sales quantity # 2. Define address and data to be stored Sadress1 = {'192.168.1.1':1} Sadress2 = {'192.168.1.2':2} Sadress3 = {'192.168.1.3':4} Sadress4 = {'192.168.1.4':6}#Data length is defined as n = 20#Determine hash value, segment is 0-1-2-4-6for one in records: if one[0] % n

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