Hashing search algorithm in JavaScript

Size
1,891 Kb
Views
10,120

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 Previews

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);
Hashing search algorithm in JavaScript - Script Codes
Hashing search algorithm in JavaScript - Script Codes
Home Page Home
Developer Tomoyuki Kashiro
Username Tkashiro
Uploaded January 19, 2023
Rating 3
Size 1,891 Kb
Views 10,120
Do you need developer help for Hashing search algorithm in JavaScript?

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!

Tomoyuki Kashiro (Tkashiro) Script Codes
Create amazing captions with AI!

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!