mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-19 09:51:33 +00:00
stdlib unlink wiring
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { LINK } from "./runtime";
|
||||
import { LINK, UNLINK } from "./runtime";
|
||||
import { HASH } from "./util/hash";
|
||||
|
||||
// A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht
|
||||
@ -93,7 +93,7 @@ export class Set<K> {
|
||||
|
||||
add(key: K): void {
|
||||
var hashCode = HASH<K>(key);
|
||||
var entry = this.find(key, hashCode);
|
||||
var entry = this.find(key, hashCode); // unmanaged!
|
||||
if (!entry) {
|
||||
// check if rehashing is necessary
|
||||
if (this.entriesOffset == this.entriesCapacity) {
|
||||
@ -108,10 +108,8 @@ export class Set<K> {
|
||||
entry = changetype<SetEntry<K>>(
|
||||
changetype<usize>(entries) + this.entriesOffset++ * ENTRY_SIZE<K>()
|
||||
);
|
||||
// link with the set itself (entry is unmanaged)
|
||||
entry.key = isManaged<K>()
|
||||
? LINK<K,this>(key, this)
|
||||
: key;
|
||||
// link with the set
|
||||
entry.key = isManaged<K>() ? LINK<K,this>(key, this) : key;
|
||||
++this.entriesCount;
|
||||
// link with previous entry in bucket
|
||||
let bucketPtrBase = changetype<usize>(this.buckets) + <usize>(hashCode & this.bucketsMask) * BUCKET_SIZE;
|
||||
@ -123,6 +121,7 @@ export class Set<K> {
|
||||
delete(key: K): bool {
|
||||
var entry = this.find(key, HASH<K>(key));
|
||||
if (!entry) return false;
|
||||
if (isManaged<K>()) UNLINK<K,this>(entry.key, this);
|
||||
entry.taggedNext |= EMPTY;
|
||||
--this.entriesCount;
|
||||
// check if rehashing is appropriate
|
||||
|
Reference in New Issue
Block a user