Skip to content

Commit

Permalink
chore: Change to MapEntry (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: IcarusTheFly <IcarusTheFly@users.noreply.github.com>
  • Loading branch information
IcarusTheFly and IcarusTheFly authored Oct 20, 2023
1 parent 9b28624 commit 4fde4fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions data_structures/map/hash_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Map } from "./map";
*/
export class HashMap<K, V> implements Map<K, V> {
private size!: number;
private buckets!: HashMapEntry<K, V>[][];
private buckets!: MapEntry<K, V>[][];
private readonly loadFactor = 0.75;

constructor() {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class HashMap<K, V> implements Map<K, V> {
const bucket = this.buckets[index];

if (bucket.length === 0) {
bucket.push(new HashMapEntry(key, value));
bucket.push(new MapEntry(key, value));
this.size++;
return;
}
Expand All @@ -59,7 +59,7 @@ export class HashMap<K, V> implements Map<K, V> {
}
}

bucket.push(new HashMapEntry(key, value));
bucket.push(new MapEntry(key, value));
this.size++;
}

Expand Down Expand Up @@ -164,8 +164,8 @@ export class HashMap<K, V> implements Map<K, V> {
*
* @returns The entries.
*/
entries(): HashMapEntry<K, V>[] {
const entries: HashMapEntry<K, V>[] = [];
entries(): MapEntry<K, V>[] {
const entries: MapEntry<K, V>[] = [];
for (const bucket of this.buckets) {
for (const entry of bucket) {
entries.push(entry);
Expand Down Expand Up @@ -228,7 +228,7 @@ export class HashMap<K, V> implements Map<K, V> {
* @param key The key.
* @param value The value.
*/
export class HashMapEntry<K, V> {
export class MapEntry<K, V> {
key: K;
value: V;

Expand Down
4 changes: 2 additions & 2 deletions data_structures/map/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HashMapEntry } from "./hash_map";
import { MapEntry } from "./hash_map";

/**
* This interface is a representation of the Map data structure.
Expand All @@ -12,5 +12,5 @@ export interface Map<K, V> {
clear(): void;
keys(): K[];
values(): V[];
entries(): HashMapEntry<K, V>[];
entries(): MapEntry<K, V>[];
}

0 comments on commit 4fde4fe

Please sign in to comment.