Last active
July 22, 2023 17:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to duplicate C#'s "Hashtable.cs" that allows duplicate keys (also note the change of script name from "DuplicateHashtable" to "GenericTable")