


PHP Core Technology and Best Practices Hash Table Conflict_PHP Tutorial
Hash table conflict between PHP core technology and best practices
Hash table conflict between PHP core technology and best practices
Following the previous article, after testing, output value1value2. When
$ht->insert(‘key12’,’value12’);
Echo $ht ->find(‘key12’);,
Found the output value12value12. What is the reason for this?
This problem is called a Hash table conflict. Since the insert is a string, the algorithm used is to add the ASIIC codes of the string. According to this method, a conflict occurs. By printing the Hash values of key12 and key1, we find that they are both 8. In other words, value1 and value12 are stored at the 9th position of the Hash table at the same time (the index starts from 0), so the value of value1 is overwritten by value12. .
Commonly used methods to resolve conflicts are: open addressing method and zipper method. Because zippers are easy to understand, this article uses the zipper method to solve conflict problems.
Zipper method to resolve conflicts:
The approach is to link all key nodes with the same Hash value in the same linked list.
The zipper method connects key nodes with the same hash value in a linked list. Then when looking for elements, you must traverse the linked list and compare whether the keyword of each element in the linked list is equal to the searched keyword. If they are equal, This is the element we are looking for.
Because nodes need to save keywords (key) and data (value), and also record nodes with the same hash value. So create a HashNode class to store this information.
The structure of HashNode is as follows:
<!--?PHP Class HashNode{ Public $key; Public $value; Public $nextNode; Public function__construct($key,$value,$nextNode = null){ $this --->key = $key; $this ->value = $value; $this ->nextNode = $nextNode; } } ?>
HashNode has 3 attributes: $key, $value, and $nextNode. $key is the key of the node, $value is the value of the node, and $nextNode is the pointer to the node with the same Hash value. Now modify the insertion method as follows:
Public function insert($key,$value){ $index= $this -> hashfunc($key); //新建一个节点 if(isset($this->buckets[$index])){ $newNode = new HashNode($key,$value,$this->buckets[$index]) }else{ $newNode = newHashNode($key,$value,null); } $this -> buckets[$index] = $newNode;//保存新节点 }
The modified insertion algorithm flow is as follows:
1) Use the Hash function to calculate the Hash value of the keyword, and locate the specified position in the Hash table through the Hash value.
2) If this position is already occupied by other nodes, point the new node's $nextNode to this node, otherwise set the new node's $nextNode to null.
3) Save the new node to the current location of the Hash table.
After these three steps, nodes with the same Hash value will be connected to the same linked list.
The search algorithm is correspondingly modified into the following format:
Public functionfind($key){ $index = $this ->hashfunc($key); $current =$this->buckets[$index]; while(isset($current)){//遍历当前链表 if($current->key== $key){ //比较当前节点的关键字 return$current -> value;//查找成功 } $current =$current ->nextNode; //比较下一个节点 } Return null; //查找失败 }
The modified search algorithm process is as follows:
1) Use the Hash function to calculate the Hash value of the keyword, and locate the specified position in the Hash table through the Hash value.
2) Traverse the current linked list and compare whether the key of each node in the linked list is equal to the search key. If they are equal, the search is successful.
3) If there is no keyword to be found in the entire linked list, the search fails.
After testing, the conflict problem was solved using the zipper method.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The first pilot and key article mainly introduces several commonly used coordinate systems in autonomous driving technology, and how to complete the correlation and conversion between them, and finally build a unified environment model. The focus here is to understand the conversion from vehicle to camera rigid body (external parameters), camera to image conversion (internal parameters), and image to pixel unit conversion. The conversion from 3D to 2D will have corresponding distortion, translation, etc. Key points: The vehicle coordinate system and the camera body coordinate system need to be rewritten: the plane coordinate system and the pixel coordinate system. Difficulty: image distortion must be considered. Both de-distortion and distortion addition are compensated on the image plane. 2. Introduction There are four vision systems in total. Coordinate system: pixel plane coordinate system (u, v), image coordinate system (x, y), camera coordinate system () and world coordinate system (). There is a relationship between each coordinate system,

Trajectory prediction plays an important role in autonomous driving. Autonomous driving trajectory prediction refers to predicting the future driving trajectory of the vehicle by analyzing various data during the vehicle's driving process. As the core module of autonomous driving, the quality of trajectory prediction is crucial to downstream planning control. The trajectory prediction task has a rich technology stack and requires familiarity with autonomous driving dynamic/static perception, high-precision maps, lane lines, neural network architecture (CNN&GNN&Transformer) skills, etc. It is very difficult to get started! Many fans hope to get started with trajectory prediction as soon as possible and avoid pitfalls. Today I will take stock of some common problems and introductory learning methods for trajectory prediction! Introductory related knowledge 1. Are the preview papers in order? A: Look at the survey first, p

StableDiffusion3’s paper is finally here! This model was released two weeks ago and uses the same DiT (DiffusionTransformer) architecture as Sora. It caused quite a stir once it was released. Compared with the previous version, the quality of the images generated by StableDiffusion3 has been significantly improved. It now supports multi-theme prompts, and the text writing effect has also been improved, and garbled characters no longer appear. StabilityAI pointed out that StableDiffusion3 is a series of models with parameter sizes ranging from 800M to 8B. This parameter range means that the model can be run directly on many portable devices, significantly reducing the use of AI

This paper explores the problem of accurately detecting objects from different viewing angles (such as perspective and bird's-eye view) in autonomous driving, especially how to effectively transform features from perspective (PV) to bird's-eye view (BEV) space. Transformation is implemented via the Visual Transformation (VT) module. Existing methods are broadly divided into two strategies: 2D to 3D and 3D to 2D conversion. 2D-to-3D methods improve dense 2D features by predicting depth probabilities, but the inherent uncertainty of depth predictions, especially in distant regions, may introduce inaccuracies. While 3D to 2D methods usually use 3D queries to sample 2D features and learn the attention weights of the correspondence between 3D and 2D features through a Transformer, which increases the computational and deployment time.

Some of the author’s personal thoughts In the field of autonomous driving, with the development of BEV-based sub-tasks/end-to-end solutions, high-quality multi-view training data and corresponding simulation scene construction have become increasingly important. In response to the pain points of current tasks, "high quality" can be decoupled into three aspects: long-tail scenarios in different dimensions: such as close-range vehicles in obstacle data and precise heading angles during car cutting, as well as lane line data. Scenes such as curves with different curvatures or ramps/mergings/mergings that are difficult to capture. These often rely on large amounts of data collection and complex data mining strategies, which are costly. 3D true value - highly consistent image: Current BEV data acquisition is often affected by errors in sensor installation/calibration, high-precision maps and the reconstruction algorithm itself. this led me to

Suddenly discovered a 19-year-old paper GSLAM: A General SLAM Framework and Benchmark open source code: https://github.com/zdzhaoyong/GSLAM Go directly to the full text and feel the quality of this work ~ 1 Abstract SLAM technology has achieved many successes recently and attracted many attracted the attention of high-tech companies. However, how to effectively perform benchmarks on speed, robustness, and portability with interfaces to existing or emerging algorithms remains a problem. In this paper, a new SLAM platform called GSLAM is proposed, which not only provides evaluation capabilities but also provides researchers with a useful way to quickly develop their own SLAM systems.

Please note that this square man is frowning, thinking about the identities of the "uninvited guests" in front of him. It turned out that she was in a dangerous situation, and once she realized this, she quickly began a mental search to find a strategy to solve the problem. Ultimately, she decided to flee the scene and then seek help as quickly as possible and take immediate action. At the same time, the person on the opposite side was thinking the same thing as her... There was such a scene in "Minecraft" where all the characters were controlled by artificial intelligence. Each of them has a unique identity setting. For example, the girl mentioned before is a 17-year-old but smart and brave courier. They have the ability to remember and think, and live like humans in this small town set in Minecraft. What drives them is a brand new,

This chip may be equipped with up to 80 GPU cores, making it the most powerful product in the M3 series. Max has twice the number of cores. Judging from the development model of the M1 and M2 series, Apple's "Ultra" version of the chip basically has twice the number of cores of the "Max" version. This is because Apple actually uses two Max chips internally. The connection technologies are combined to form M1Ultra and M2Ultra. 80 GPU cores M3Ultra may have "up to 80 graphics processing cores." This prediction is based on the development path of Apple's chips: from the basic version to the "Pro" version, to the "Max" version with twice the number of graphics cores, and the "Ultra" version with double the number of CPU and GPU cores. For example
