Skip to content

Instantly share code, notes, and snippets.

@RyanGarber
Last active July 22, 2023 17:44
Show Gist options
  • Save RyanGarber/10921169 to your computer and use it in GitHub Desktop.
Save RyanGarber/10921169 to your computer and use it in GitHub Desktop.
A weird workaround I created when I was 14 years old, kept here only for sentimental value
using System.Collections.Generic;
public class GenericTable<T, U> {
private List<GenericTableEntry> Table = new List<GenericTableEntry>();
public void Add(T Key, U Value) {
Table.Add(new GenericTableEntry(Key, Value));
}
public GenericTableEntry[] GetAll() {
return Table.ToArray();
}
public U[] GetValues(T Key) {
List<U> Entries = new List<U>();
foreach(GenericTableEntry Entry in Table) if(Entry.GetKey().Equals(Key)) Entries.Add(Entry.GetValue());
return Entries.ToArray();
}
public T[] GetKeys(U Value) {
List<T> Entries = new List<T>();
foreach(GenericTableEntry Entry in Table) if(Entry.GetValue().Equals(Value)) Entries.Add(Entry.GetKey());
return Entries.ToArray();
}
public void Add(GenericTableEntry[] Entries) {
Table.AddRange(Entries);
}
public class GenericTableEntry {
private T Key;
private U Value;
public GenericTableEntry(T Key, U Value) {
this.Key = Key;
this.Value = Value;
}
public T GetKey() {
return Key;
}
public U GetValue() {
return Value;
}
}
}
@hintss
Copy link

hintss commented Apr 17, 2014

you lied, it's not a hashtable, just a table. needs more trees.

@RyanGarber
Copy link
Author

I tried to duplicate C#'s "Hashtable.cs" that allows duplicate keys (also note the change of script name from "DuplicateHashtable" to "GenericTable")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment