Skip to content

Instantly share code, notes, and snippets.

View graphoarty's full-sized avatar
🎯
Focusing

Quinston Pimenta graphoarty

🎯
Focusing
  • https://quinston.com
  • Pune, India
View GitHub Profile
from hashlib import md5
from DataStructures.LinkedList.LinkedList import *
defaultHashTableSize = 32
class HashTable:
# @param {number} hashTableSize
def __init__(self, hashTableSize = defaultHashTableSize):
# Should probably be named HashTableEntry. You get the point.
self.buckets = [LinkedList() for x in range(0, hashTableSize)]
# A quick lookup for has() and getKeys().
self.keys = {}
# @params {string} key
# @returns {number}
def hash(self, key):
k = 0
for s in list(md5(str(key).encode('utf-8')).hexdigest()):
k += ord(s)
return k % len(self.buckets)
# @param {string} key
# @param {*} value
def set(self, key, value):
keyHash = self.hash(key)
self.keys[key] = keyHash
bucketLinkedList = self.buckets[keyHash]
# custom linkedlist find
node = None
# @param {string} key
# @returns {*}
def get(self, key):
bucketLinkedList = self.buckets[self.hash(key)]
# custom linkedlist find
currentNode = bucketLinkedList.head
while not currentNode == None:
for k in currentNode.value:
# @params {string} key
# @returns {boolean}
def has(self, key):
if key in self.keys.keys():
return True
else:
return False
# @returns {string[]}
def getKeys(self):
@graphoarty
graphoarty / asyncScript.js
Created February 20, 2019 08:09
Import Asynchronous (async) JavaScript (js) Script in Reactjs
// Example Call
// asyncScript('https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
asyncScript = (scriptPath) => {
const script = document.createElement('script');
script.src = scriptPath;
script.async = true;
document.body.appendChild(script);
@graphoarty
graphoarty / da.java
Created February 21, 2019 14:23
Dijkstra's Algorithm
import java.util.Scanner; //Scanner Function to take in the Input Values
public class Dijkstra {
static Scanner scan; // scan is a Scanner Object
public static void main(String[] args){
int[] preD = new int[5];
int min = 999, nextNode = 0; // min holds the minimum value, nextNode holds the value for the next node.