Hashing search algorithm in JavaScript
How do I make an hashing search algorithm in javascript?
What is a hashing search algorithm in javascript? How do you make a hashing search algorithm in javascript? This script and codes were developed by Tomoyuki Kashiro on 19 January 2023, Thursday.
Hashing search algorithm in JavaScript - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Hashing search algorithm in JavaScript</title>
</head>
<body> <h1>Hashing search algorithm in JavaScript</h1>
<p>Please check javascript code.</p> <script src="js/index.js"></script>
</body>
</html>
Hashing search algorithm in JavaScript - Script Codes JS Codes
/*************************************** * util ***************************************/
var initData = function(list){ for(var i = 0; i < list.length; i++){ list[i] = 0; } return list;
};
/*************************************** * set ***************************************/
var setData = function(data, targets){ var key, length = targets.length, max = targets.length-1; data.forEach(function(value){ key = value % length; if(targets[key] === 0){ targets[key] = value; }else{ while(true){ key++; // next to or start if(key === max){ key = 0; } if(targets[key] === 0){ targets[key] = value; break; } } } }); return targets;
};
/*************************************** * search ***************************************/
var hashSearch = function(value, list){ var length = list.length, max = list.length -1, key = value % length, target; while(true){ target = list[key]; if(target === value){ break; } if(key === max){ key = 0; }else{ key++; } } return key;
};
/*************************************** * main ***************************************/
var rawData = [12,25,36,20,30,8,41], data = new Array(rawData.length * 2), // prepare * 1.5 - 2 length target = 36, result;
data = initData(data);
data = setData(rawData, data); // [0, 0, 30, 0, 0, 0, 20, 0, 36, 8, 0, 25, 12, 41]
result = hashSearch(target, data);
console.log('index of tartget(' + target + ') is ' + result);
Developer | Tomoyuki Kashiro |
Username | Tkashiro |
Uploaded | January 19, 2023 |
Rating | 3 |
Size | 1,891 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Bubble sort algorithm in JavaScrip | 1,713 Kb |
Get css mediaquery breakpoint using js | 2,502 Kb |
3 lines menu button | 3,564 Kb |
Simple arc animation | 4,136 Kb |
Css resolution | 2,218 Kb |
CSS multi-column layout | 2,627 Kb |
Shadow Dom Test | 2,204 Kb |
Spotlight Effect | 2,723 Kb |
Binary search algorithm in JavaScript | 1,798 Kb |
Media Fragments URI | 1,753 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
12 DAYS OF XMAS | Proto78 | 2,313 Kb |
Simple blog concept | Drew_mc | 2,666 Kb |
AOR site logo | Thatbram | 2,527 Kb |
A Pen by Andrea Berardi | Aberry | 1,330 Kb |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
Fireworks Show | Arianalynn | 3,048 Kb |
TheCalendar.js | The-teacher | 6,330 Kb |
Week7 replicate | Hwcasis | 1,620 Kb |
Sencha Touch 2.3.1 Basic Grid Example | Trozdol | 2,770 Kb |
Canvas stripes | Adrianparr | 1,948 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!