Add generics example
This commit is contained in:
46
tests/generics.sols
Normal file
46
tests/generics.sols
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user