hash list

by Juan Alban Franco

HTML

<html>
<head>

</head>
<body>
<input type = textbox id = in value = 'Insert Password'><input type = button id = insert_pass onclick = "input()" value = "Submit password" >
<br>
<br>
<input type = textbox id = ch value = 'Check for Password'><input type = button id = search value = 'Search for Password' onclick = search()>
<br><br>
<p id = out>




</body></html>

JavaScript

function SList() 
{
	this.head = null;
  this.tail = null;
	this.length = null;
}

function Node(){
	this.key = null;
  this.next = null;
}

SList.prototype.hash = function (_Key){
var hash = '', i=0,char='';
if (_Key.length ===0){
	this.addnode(hash);
}
else{
	for (i = 0; i<_Key.length; i++){
  	char = _Key.charCodeAt(i);
    hash = ((hash << 5) - hash)+char;
    hash = hash & hash;
  }
  
}
console.log(hash);
return hash;

}

SList.prototype.search  = function(_Search){
	var search = this.hash(_Search)
	var traveler = new Node();
  traveler = this.head; 
  while(traveler){
  if(traveler.key == search){globalstring = traveler.key;return 1;}
  traveler = traveler.next;
  }
return 0;
}


SList.prototype.addnode = function(_Key){
	var node = new Node();
  node.key = _Key;
  
  if(this.tail==null && this.head ==null){
  	this.tail = node;
    this.head = node;
    node.next = null;
    this.length ++;
  }
  else 
  	this.tail.next = node;
    this.tail = node;
}

list = new SList();

function input() {
	var string = document.getElementById("in").value;
  console.log(string);
  var hash = 0;
  hash = list.hash(string);
  list.addnode(hash);
}
var globalstring='';
function search(){
var string = document.getElementById("ch").value;
var bool = -1;
bool = list.search(string);
if(bool > 0){document.getElementById("out").innerHTML = "The Password exists in the list with value " + globalstring }
else{document.getElementById("out").innerHTML = "The phrase you have entered does not exists in the list"}
}