Skip to content
Snippets Groups Projects
Commit f6e881d2 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Updated lab for 2019.

parent 580461a3
Branches
No related tags found
No related merge requests found
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
"browser": true, "browser": true,
"jquery": true, "jquery": true,
}, },
"parserOptions": {
"sourceType": "module",
},
"rules": { "rules": {
"no-await-in-loop": "warn", "no-await-in-loop": "warn",
"no-compare-neg-zero": "warn", "no-compare-neg-zero": "warn",
......
...@@ -6,15 +6,13 @@ ...@@ -6,15 +6,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hashing</title> <title>Hashing</title>
<link rel="stylesheet" type="text/css" href="css/index.css"> <link rel="stylesheet" type="text/css" href="css/index.css">
<script defer="true" src="libraries/jquery/jquery.min.js"></script>
<script defer="true" type="module" src="js/index.js"></script>
</head> </head>
<body> <body>
<div id="time"></div> <div id="time"></div>
<div id="freeness"></div> <div id="freeness"></div>
<script src="libraries/jquery/jquery.min.js"></script>
<script src="js/hash_table.js"></script>
<script src="js/words.js"></script>
<script src="js/index.js"></script>
</body> </body>
</html> </html>
/* exported HashTable */
function mod(value, modulus) { function mod(value, modulus) {
const result = value % modulus; const result = value % modulus;
return result < 0 ? result + modulus : result; return result < 0 ? result + modulus : result;
...@@ -38,7 +36,7 @@ function createBuckets(count) { ...@@ -38,7 +36,7 @@ function createBuckets(count) {
const INITIAL_HASH_TABLE_CAPACITY = 7; // eslint-disable-line no-magic-numbers const INITIAL_HASH_TABLE_CAPACITY = 7; // eslint-disable-line no-magic-numbers
const MAXIMUM_LOAD_FACTOR = 2 / 3; // eslint-disable-line no-magic-numbers const MAXIMUM_LOAD_FACTOR = 2 / 3; // eslint-disable-line no-magic-numbers
class HashTable { export class HashTable {
constructor(hashFunction) { constructor(hashFunction) {
this._hashFunction = (element) => mod(hashFunction(element), this._buckets.length); this._hashFunction = (element) => mod(hashFunction(element), this._buckets.length);
this._buckets = createBuckets(increaseToPseudoPrime(INITIAL_HASH_TABLE_CAPACITY)); this._buckets = createBuckets(increaseToPseudoPrime(INITIAL_HASH_TABLE_CAPACITY));
......
/* globals HashTable DICTIONARY */ import {HashTable} from './hash_table.js';
import {DICTIONARY} from './words.js';
/* eslint-disable no-magic-numbers */ /* eslint-disable no-magic-numbers */
......
/* exported DICTIONARY */ export const DICTIONARY = [
const DICTIONARY = [
"A", "A",
"AA", "AA",
"AAA", "AAA",
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment