most of hash map - have to commit fix for unify type first
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import mem
|
||||
import io
|
||||
import set
|
||||
import map
|
||||
import vector
|
||||
import serialize
|
||||
|
||||
|
||||
// maybe my favorite function
|
||||
fun do_nothing() {}
|
||||
|
||||
@@ -25,6 +27,16 @@ fun min<T>(a: T, b: T): T {
|
||||
return a;
|
||||
}
|
||||
|
||||
fun hash<T(Hashable)>(item: T): int return item.hash()
|
||||
fun hash<T>(item: *T): int return (item) cast int
|
||||
fun hash(item: int): int return item
|
||||
fun hash(item: char): int return item
|
||||
// default hash
|
||||
fun hash<T>(item: T): int {
|
||||
io::println("using empty hash - please do not do!")
|
||||
return 0
|
||||
}
|
||||
|
||||
fun make_pair<T,U>(first: T, second: U): pair<T,U> {
|
||||
var it.construct(first, second): pair<T,U>
|
||||
return it
|
||||
@@ -46,7 +58,7 @@ obj unpack_dummy<T,U> {
|
||||
}
|
||||
}
|
||||
|
||||
obj pair<T,U> (Object, Serializable) {
|
||||
obj pair<T,U> (Object, Serializable, Hashable) {
|
||||
var first: T
|
||||
var second: U
|
||||
|
||||
@@ -83,6 +95,9 @@ obj pair<T,U> (Object, Serializable) {
|
||||
return second_pair.second
|
||||
}
|
||||
|
||||
/*fun hash():int return hash(first) ^ hash(second)*/
|
||||
fun hash():int return 0
|
||||
|
||||
// the old unnecessary template to prevent generation
|
||||
// if not used trick (in this case, changing out U with V)
|
||||
fun operator==<V>(other: ref pair<T,V>): bool {
|
||||
|
||||
Reference in New Issue
Block a user