Add generics example

This commit is contained in:
2026-04-14 09:21:30 +10:00
parent 23041c041a
commit f127c2f5ab

46
tests/generics.sols Normal file
View File

@@ -0,0 +1,46 @@
struct Hash {
protected hashstr = ""
}
struct Person {
age = 0
name = ""
constructor(int age, string name) {
self.age = age
self.name = name
}
as Hash {
// hash the Person here
}
}
struct HashTable<Key can Hash, Value> {
private ptr = 0
protected size = 0
private capacity = 0
def find(Key key) {
hash = key as Hash
// find in table using hash
}
def set(Key key, Value value) {
hash = key as Hash
// store Value in the table
}
constructor() {
// malloc the pointer and set up hash information
}
duplicator {
// copy all contents
}
destructor {
// free the ptr
}
}