runtime: add unsafe.pointer reflect wrappers for hashmap calls
Этот коммит содержится в:
родитель
9541525402
коммит
c0a50e9b47
1 изменённых файлов: 46 добавлений и 4 удалений
|
@ -49,6 +49,10 @@ type hashmapIterator struct {
|
||||||
bucketIndex uint8 // current index into bucket
|
bucketIndex uint8 // current index into bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapNewIterator() unsafe.Pointer {
|
||||||
|
return unsafe.Pointer(new(hashmapIterator))
|
||||||
|
}
|
||||||
|
|
||||||
// Get the topmost 8 bits of the hash, without using a special value (like 0).
|
// Get the topmost 8 bits of the hash, without using a special value (like 0).
|
||||||
func hashmapTopHash(hash uint32) uint8 {
|
func hashmapTopHash(hash uint32) uint8 {
|
||||||
tophash := uint8(hash >> 24)
|
tophash := uint8(hash >> 24)
|
||||||
|
@ -84,6 +88,10 @@ func hashmapMake(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) *hashm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapMakeUnsafePointer(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) unsafe.Pointer {
|
||||||
|
return (unsafe.Pointer)(hashmapMake(keySize, valueSize, sizeHint, alg))
|
||||||
|
}
|
||||||
|
|
||||||
func hashmapKeyEqualAlg(alg hashmapAlgorithm) func(x, y unsafe.Pointer, n uintptr) bool {
|
func hashmapKeyEqualAlg(alg hashmapAlgorithm) func(x, y unsafe.Pointer, n uintptr) bool {
|
||||||
switch alg {
|
switch alg {
|
||||||
case hashmapAlgorithmBinary:
|
case hashmapAlgorithmBinary:
|
||||||
|
@ -142,10 +150,8 @@ func hashmapLen(m *hashmap) int {
|
||||||
return int(m.count)
|
return int(m.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrapper for use in reflect
|
func hashmapLenUnsafePointer(m unsafe.Pointer) int {
|
||||||
func hashmapLenUnsafePointer(p unsafe.Pointer) int {
|
return hashmapLen((*hashmap)(m))
|
||||||
m := (*hashmap)(p)
|
|
||||||
return hashmapLen(m)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a specified key to a given value. Grow the map if necessary.
|
// Set a specified key to a given value. Grow the map if necessary.
|
||||||
|
@ -208,6 +214,10 @@ func hashmapSet(m *hashmap, key unsafe.Pointer, value unsafe.Pointer, hash uint3
|
||||||
*emptySlotTophash = tophash
|
*emptySlotTophash = tophash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapSetUnsafePointer(m unsafe.Pointer, key unsafe.Pointer, value unsafe.Pointer, hash uint32) {
|
||||||
|
hashmapSet((*hashmap)(m), key, value, hash)
|
||||||
|
}
|
||||||
|
|
||||||
// hashmapInsertIntoNewBucket creates a new bucket, inserts the given key and
|
// hashmapInsertIntoNewBucket creates a new bucket, inserts the given key and
|
||||||
// value into the bucket, and returns a pointer to this bucket.
|
// value into the bucket, and returns a pointer to this bucket.
|
||||||
func hashmapInsertIntoNewBucket(m *hashmap, key, value unsafe.Pointer, tophash uint8) *hashmapBucket {
|
func hashmapInsertIntoNewBucket(m *hashmap, key, value unsafe.Pointer, tophash uint8) *hashmapBucket {
|
||||||
|
@ -299,6 +309,10 @@ func hashmapGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr, hash u
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapGetUnsafePointer(m unsafe.Pointer, key, value unsafe.Pointer, valueSize uintptr, hash uint32) bool {
|
||||||
|
return hashmapGet((*hashmap)(m), key, value, valueSize, hash)
|
||||||
|
}
|
||||||
|
|
||||||
// Delete a given key from the map. No-op when the key does not exist in the
|
// Delete a given key from the map. No-op when the key does not exist in the
|
||||||
// map.
|
// map.
|
||||||
//
|
//
|
||||||
|
@ -409,6 +423,10 @@ func hashmapNext(m *hashmap, it *hashmapIterator, key, value unsafe.Pointer) boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapNextUnsafePointer(m unsafe.Pointer, it unsafe.Pointer, key, value unsafe.Pointer) bool {
|
||||||
|
return hashmapNext((*hashmap)(m), (*hashmapIterator)(it), key, value)
|
||||||
|
}
|
||||||
|
|
||||||
// Hashmap with plain binary data keys (not containing strings etc.).
|
// Hashmap with plain binary data keys (not containing strings etc.).
|
||||||
func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
|
func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
|
@ -418,6 +436,10 @@ func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
|
||||||
hashmapSet(m, key, value, hash)
|
hashmapSet(m, key, value, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapBinarySetUnsafePointer(m unsafe.Pointer, key, value unsafe.Pointer) {
|
||||||
|
hashmapBinarySet((*hashmap)(m), key, value)
|
||||||
|
}
|
||||||
|
|
||||||
func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr) bool {
|
func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr) bool {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
memzero(value, uintptr(valueSize))
|
memzero(value, uintptr(valueSize))
|
||||||
|
@ -427,6 +449,10 @@ func hashmapBinaryGet(m *hashmap, key, value unsafe.Pointer, valueSize uintptr)
|
||||||
return hashmapGet(m, key, value, valueSize, hash)
|
return hashmapGet(m, key, value, valueSize, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapBinaryGetUnsafePointer(m unsafe.Pointer, key, value unsafe.Pointer, valueSize uintptr) bool {
|
||||||
|
return hashmapBinaryGet((*hashmap)(m), key, value, valueSize)
|
||||||
|
}
|
||||||
|
|
||||||
func hashmapBinaryDelete(m *hashmap, key unsafe.Pointer) {
|
func hashmapBinaryDelete(m *hashmap, key unsafe.Pointer) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return
|
return
|
||||||
|
@ -435,6 +461,10 @@ func hashmapBinaryDelete(m *hashmap, key unsafe.Pointer) {
|
||||||
hashmapDelete(m, key, hash)
|
hashmapDelete(m, key, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapBinaryDeleteUnsafePointer(m unsafe.Pointer, key unsafe.Pointer) {
|
||||||
|
hashmapBinaryDelete((*hashmap)(m), key)
|
||||||
|
}
|
||||||
|
|
||||||
// Hashmap with string keys (a common case).
|
// Hashmap with string keys (a common case).
|
||||||
|
|
||||||
func hashmapStringEqual(x, y unsafe.Pointer, n uintptr) bool {
|
func hashmapStringEqual(x, y unsafe.Pointer, n uintptr) bool {
|
||||||
|
@ -459,6 +489,10 @@ func hashmapStringSet(m *hashmap, key string, value unsafe.Pointer) {
|
||||||
hashmapSet(m, unsafe.Pointer(&key), value, hash)
|
hashmapSet(m, unsafe.Pointer(&key), value, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapStringSetUnsafePointer(m unsafe.Pointer, key string, value unsafe.Pointer) {
|
||||||
|
hashmapStringSet((*hashmap)(m), key, value)
|
||||||
|
}
|
||||||
|
|
||||||
func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer, valueSize uintptr) bool {
|
func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer, valueSize uintptr) bool {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
memzero(value, uintptr(valueSize))
|
memzero(value, uintptr(valueSize))
|
||||||
|
@ -468,6 +502,10 @@ func hashmapStringGet(m *hashmap, key string, value unsafe.Pointer, valueSize ui
|
||||||
return hashmapGet(m, unsafe.Pointer(&key), value, valueSize, hash)
|
return hashmapGet(m, unsafe.Pointer(&key), value, valueSize, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapStringGetUnsafePointer(m unsafe.Pointer, key string, value unsafe.Pointer, valueSize uintptr) bool {
|
||||||
|
return hashmapStringGet((*hashmap)(m), key, value, valueSize)
|
||||||
|
}
|
||||||
|
|
||||||
func hashmapStringDelete(m *hashmap, key string) {
|
func hashmapStringDelete(m *hashmap, key string) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return
|
return
|
||||||
|
@ -476,6 +514,10 @@ func hashmapStringDelete(m *hashmap, key string) {
|
||||||
hashmapDelete(m, unsafe.Pointer(&key), hash)
|
hashmapDelete(m, unsafe.Pointer(&key), hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashmapStringDeleteUnsafePointer(m unsafe.Pointer, key string) {
|
||||||
|
hashmapStringDelete((*hashmap)(m), key)
|
||||||
|
}
|
||||||
|
|
||||||
// Hashmap with interface keys (for everything else).
|
// Hashmap with interface keys (for everything else).
|
||||||
|
|
||||||
// This is a method that is intentionally unexported in the reflect package. It
|
// This is a method that is intentionally unexported in the reflect package. It
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче