Skip to content

Change HashMapEntry to MapEntry #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>[];
}