Preliminary implementation of a hashmap, unfinished

Missing features:
  * keys other than strings
  * more than 8 values in the hashmap
  * growing a map when needed
  * initial size hint
  * delete(m, key)
  * iterators (for range)
  * initializing global maps
  * ...more?
This commit is contained in:
Ayke van Laethem
2018-08-22 04:50:24 +02:00
parent 8fb9cd4e23
commit 3a6ef38041
5 changed files with 290 additions and 21 deletions
+18
View File
@@ -1,5 +1,9 @@
package runtime
import (
"unsafe"
)
const Compiler = "tgo"
// The bitness of the CPU (e.g. 8, 32, 64). Set by the compiler as a constant.
@@ -29,6 +33,20 @@ func stringequal(x, y string) bool {
return true
}
// Copy size bytes from src to dst. The memory areas must not overlap.
func memcpy(dst, src unsafe.Pointer, size uintptr) {
for i := uintptr(0); i < size; i++ {
*(*uint8)(unsafe.Pointer(uintptr(dst) + i)) = *(*uint8)(unsafe.Pointer(uintptr(src) + i))
}
}
// Set the given number of bytes to zero.
func memzero(ptr unsafe.Pointer, size uintptr) {
for i := uintptr(0); i < size; i++ {
*(*byte)(unsafe.Pointer(uintptr(ptr) + size)) = 0
}
}
func _panic(message interface{}) {
printstring("panic: ")
printitf(message)