github.com/matrixorigin/matrixone@v0.7.0/pkg/container/hashtable/bucket.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package hashtable 16 17 import ( 18 "unsafe" 19 20 "github.com/matrixorigin/matrixone/pkg/common/mpool" 21 ) 22 23 func (ht *StringHashMap) InsertStringBatchInBucket(states [][3]uint64, keys [][]byte, values []uint64, ibucket, nbucket uint64, m *mpool.MPool) error { 24 if err := ht.resizeOnDemand(uint64(len(keys)), m); err != nil { 25 return err 26 } 27 28 BytesBatchGenHashStates(&keys[0], &states[0], len(keys)) 29 30 for i := range keys { 31 if states[i][0]%nbucket != ibucket { 32 values[i] = 0 33 continue 34 } 35 cell := ht.findCell(&states[i]) 36 if cell.Mapped == 0 { 37 ht.elemCnt++ 38 cell.HashState = states[i] 39 cell.Mapped = ht.elemCnt 40 } 41 values[i] = cell.Mapped 42 } 43 return nil 44 } 45 46 /* 47 func (ht *StringHashMap) InsertString24BatchInBucket(states [][3]uint64, keys [][3]uint64, values []uint64, ibucket, nbucket uint64) { 48 ht.resizeOnDemand(uint64(len(keys))) 49 50 AesInt192BatchGenHashStates(&keys[0], &states[0], len(keys)) 51 52 for i := range keys { 53 if states[i][0]%nbucket != ibucket { 54 continue 55 } 56 cell := ht.findCell(&states[i]) 57 if cell.Mapped == 0 { 58 ht.elemCnt++ 59 cell.HashState = states[i] 60 cell.Mapped = ht.elemCnt 61 } 62 values[i] = cell.Mapped 63 } 64 } 65 66 func (ht *StringHashMap) InsertString32BatchInBucket(states [][3]uint64, keys [][4]uint64, values []uint64, ibucket, nbucket uint64) { 67 ht.resizeOnDemand(uint64(len(keys))) 68 69 AesInt256BatchGenHashStates(&keys[0], &states[0], len(keys)) 70 71 for i := range keys { 72 if states[i][0]%nbucket != ibucket { 73 continue 74 } 75 cell := ht.findCell(&states[i]) 76 if cell.Mapped == 0 { 77 ht.elemCnt++ 78 cell.HashState = states[i] 79 cell.Mapped = ht.elemCnt 80 } 81 values[i] = cell.Mapped 82 } 83 } 84 85 func (ht *StringHashMap) InsertString40BatchInBucket(states [][3]uint64, keys [][5]uint64, values []uint64, ibucket, nbucket uint64) { 86 ht.resizeOnDemand(uint64(len(keys))) 87 88 AesInt320BatchGenHashStates(&keys[0], &states[0], len(keys)) 89 90 for i := range keys { 91 if states[i][0]%nbucket != ibucket { 92 continue 93 } 94 cell := ht.findCell(&states[i]) 95 if cell.Mapped == 0 { 96 ht.elemCnt++ 97 cell.HashState = states[i] 98 cell.Mapped = ht.elemCnt 99 } 100 values[i] = cell.Mapped 101 } 102 } 103 */ 104 105 func (ht *StringHashMap) InsertStringBatchWithRingInBucket(zValues []int64, states [][3]uint64, keys [][]byte, values []uint64, ibucket, nbucket uint64, m *mpool.MPool) error { 106 if err := ht.resizeOnDemand(uint64(len(keys)), m); err != nil { 107 return err 108 } 109 110 BytesBatchGenHashStates(&keys[0], &states[0], len(keys)) 111 112 for i := range keys { 113 if zValues[i] == 0 { 114 continue 115 } 116 if states[i][0]%nbucket != ibucket { 117 values[i] = 0 118 continue 119 } 120 121 cell := ht.findCell(&states[i]) 122 if cell.Mapped == 0 { 123 ht.elemCnt++ 124 cell.HashState = states[i] 125 cell.Mapped = ht.elemCnt 126 } 127 values[i] = cell.Mapped 128 } 129 return nil 130 } 131 132 /* 133 func (ht *StringHashMap) InsertString24BatchWithRingInBucket(zValues []int64, states [][3]uint64, keys [][3]uint64, values []uint64, ibucket, nbucket uint64) { 134 ht.resizeOnDemand(uint64(len(keys))) 135 136 AesInt192BatchGenHashStates(&keys[0], &states[0], len(keys)) 137 138 for i := range keys { 139 if zValues[i] == 0 { 140 continue 141 } 142 if states[i][0]%nbucket != ibucket { 143 continue 144 } 145 146 cell := ht.findCell(&states[i]) 147 if cell.Mapped == 0 { 148 ht.elemCnt++ 149 cell.HashState = states[i] 150 cell.Mapped = ht.elemCnt 151 } 152 values[i] = cell.Mapped 153 } 154 } 155 156 func (ht *StringHashMap) InsertString32BatchWithRingInBucket(zValues []int64, states [][3]uint64, keys [][4]uint64, values []uint64, ibucket, nbucket uint64) { 157 ht.resizeOnDemand(uint64(len(keys))) 158 159 AesInt256BatchGenHashStates(&keys[0], &states[0], len(keys)) 160 161 for i := range keys { 162 if zValues[i] == 0 { 163 continue 164 } 165 if states[i][0]%nbucket != ibucket { 166 continue 167 } 168 169 cell := ht.findCell(&states[i]) 170 if cell.Mapped == 0 { 171 ht.elemCnt++ 172 cell.HashState = states[i] 173 cell.Mapped = ht.elemCnt 174 } 175 values[i] = cell.Mapped 176 } 177 } 178 179 func (ht *StringHashMap) InsertString40BatchWithRingInBucket(zValues []int64, states [][3]uint64, keys [][5]uint64, values []uint64, ibucket, nbucket uint64) { 180 ht.resizeOnDemand(uint64(len(keys))) 181 182 AesInt320BatchGenHashStates(&keys[0], &states[0], len(keys)) 183 184 for i := range keys { 185 if zValues[i] == 0 { 186 continue 187 } 188 if states[i][0]%nbucket != ibucket { 189 continue 190 } 191 192 cell := ht.findCell(&states[i]) 193 if cell.Mapped == 0 { 194 ht.elemCnt++ 195 cell.HashState = states[i] 196 cell.Mapped = ht.elemCnt 197 } 198 values[i] = cell.Mapped 199 } 200 } 201 */ 202 203 func (ht *StringHashMap) FindStringBatchInBucket(states [][3]uint64, keys [][]byte, values []uint64, inBuckets []uint8, ibucket, nbucket uint64) { 204 BytesBatchGenHashStates(&keys[0], &states[0], len(keys)) 205 206 for i := range keys { 207 if states[i][0]%nbucket != ibucket { 208 inBuckets[i] = 0 // mark of 0 means it is not in the processed bucket 209 continue 210 } 211 cell := ht.findCell(&states[i]) 212 values[i] = cell.Mapped 213 } 214 } 215 216 func (ht *StringHashMap) FindStringBatchWithRingInBucket(states [][3]uint64, zValues []int64, keys [][]byte, values []uint64, inBuckets []uint8, ibucket, nbucket uint64) { 217 BytesBatchGenHashStates(&keys[0], &states[0], len(keys)) 218 219 for i := range keys { 220 if states[i][0]%nbucket != ibucket { 221 inBuckets[i] = 0 // mark of 0 means it is not in the processed bucket 222 continue 223 } 224 if zValues[i] == 0 { 225 values[i] = 0 226 continue 227 } 228 cell := ht.findCell(&states[i]) 229 values[i] = cell.Mapped 230 } 231 } 232 233 func (ht *Int64HashMap) InsertBatchInBucket(n int, hashes []uint64, keysPtr unsafe.Pointer, values []uint64, ibucket, nbucket uint64, m *mpool.MPool) error { 234 if err := ht.resizeOnDemand(n, m); err != nil { 235 return err 236 } 237 238 if hashes[0] == 0 { 239 Int64BatchHash(keysPtr, &hashes[0], n) 240 } 241 242 keys := unsafe.Slice((*uint64)(keysPtr), n) 243 244 for i, key := range keys { 245 if hashes[i]%nbucket != ibucket { 246 values[i] = 0 247 continue 248 } 249 cell := ht.findCell(hashes[i], key) 250 if cell.Mapped == 0 { 251 ht.elemCnt++ 252 cell.Key = key 253 cell.Mapped = ht.elemCnt 254 } 255 values[i] = cell.Mapped 256 } 257 return nil 258 } 259 260 func (ht *Int64HashMap) InsertBatchWithRingInBucket(n int, zValues []int64, hashes []uint64, keysPtr unsafe.Pointer, values []uint64, ibucket, nbucket uint64, m *mpool.MPool) error { 261 if err := ht.resizeOnDemand(n, m); err != nil { 262 return err 263 } 264 265 if hashes[0] == 0 { 266 Int64BatchHash(keysPtr, &hashes[0], n) 267 } 268 269 keys := unsafe.Slice((*uint64)(keysPtr), n) 270 for i, key := range keys { 271 if zValues[i] == 0 { 272 continue 273 } 274 if hashes[i]%nbucket != ibucket { 275 values[i] = 0 276 continue 277 } 278 cell := ht.findCell(hashes[i], key) 279 if cell.Mapped == 0 { 280 ht.elemCnt++ 281 cell.Key = key 282 cell.Mapped = ht.elemCnt 283 } 284 values[i] = cell.Mapped 285 } 286 return nil 287 } 288 289 func (ht *Int64HashMap) FindBatchInBucket(n int, hashes []uint64, keysPtr unsafe.Pointer, values []uint64, inBuckets []uint8, ibucket, nbucket uint64) { 290 if hashes[0] == 0 { 291 Int64BatchHash(keysPtr, &hashes[0], n) 292 } 293 294 keys := unsafe.Slice((*uint64)(keysPtr), n) 295 for i, key := range keys { 296 if hashes[i]%nbucket != ibucket { 297 inBuckets[i] = 0 // mark of 0 means it is not in the processed bucket 298 continue 299 } 300 cell := ht.findCell(hashes[i], key) 301 values[i] = cell.Mapped 302 } 303 } 304 305 func (ht *Int64HashMap) FindBatchWithRingInBucket(n int, zValues []int64, hashes []uint64, keysPtr unsafe.Pointer, values []uint64, inBuckets []uint8, ibucket, nbucket uint64) { 306 if hashes[0] == 0 { 307 Int64BatchHash(keysPtr, &hashes[0], n) 308 } 309 310 keys := unsafe.Slice((*uint64)(keysPtr), n) 311 for i, key := range keys { 312 if hashes[i]%nbucket != ibucket { 313 inBuckets[i] = 0 // mark of 0 means it is not in the processed bucket 314 continue 315 } 316 if zValues[i] == 0 { 317 values[i] = 0 318 continue 319 } 320 cell := ht.findCell(hashes[i], key) 321 values[i] = cell.Mapped 322 } 323 }