//! //! Efficient hash set for short(ish) strings. //! //! Layout: []Bucket //! //! * Bucket: [8]Sector //! //! * Sector: [8]u8 or u64 //! //! Strategy: Hybrid between open addressing with linear probing, and chaining, //! with special markers for indirection; see details below. //! //! The Zisp parser interns strings up to 255 bytes in length, using the `Istr` //! heap representation with a len prefix of one byte and hash cache suffix of //! eight bytes. This means that strings of up to 55 bytes of content can fit //! within 64 bytes. We store these inline in our buckets. A pointer to that //! bucket is then itself the Istr. //! //! A bucket can contain multiple strings if they fit. The strings are aligned //! at 8 byte "sectors" so a pointer to a sector can also be a valid Istr. //! //! A sector may appear empty (all 0 bytes) but actually be part of a string; //! this is not a problem since strings are length-prefixed. Linear probing //! starts at the beginning of a bucket, and jumps over occupied sectors as //! indicated by a string's length prefix. This can continue across buckets. //! When an empty sector is found after jumping over a string, we check if //! there's enough space within the bucket to hold the string, otherwise we //! advance into the next bucket and keep probing. //! //! Splitting across buckets is not allowed, since this introduces ambiguity: //! Strings can contain ASCII NUL bytes, so if a string ending in a series of //! NUL bytes were allowed to spill into the next bucket, it would appear to //! begin with an empty sector. A later probe sequence beginning with that //! bucket would then see it as empty and overwrite part of another string. //! //! Since strings up to 6 bytes are packed into NaN, they can never appear here, //! which means the empty string cannot appear, so a length prefix cannot be 0. //! Thus there's no ambiguity between empty sector and empty string. //! //! A sector can begin with a 0 byte, but have a non-0 value as a u64; this //! indicates a packed pointer to an Istr elsewhere on the heap. The low 48 //! bits are the pointer, while the high bits encode the length of the string //! being pointed to, so we don't need to follow the pointer for the equality //! check in case the lengths are different. Also, in this case, the cached //! hash follows directly in the next sector, so we also needn't follow the //! pointer when resizing the hash set. //! /// Bucket count bcount: usize = 512, // 512 used_bytes: usize, total_bytes: usize,