phobic.rs
cdk-rsx/crates/cdk-rsx-collections-minima/src/phobic.rs
1// SPDX-License-Identifier: Apache-2.02//! PHOBIC minimal perfect hashing with optimized buckets and interleaved seeds.3//!4//! Hermann, Lehmann, Pibiri, Sanders and Walzer, *PHOBIC: Perfect Hashing with5//! Optimized Bucket Sizes and Interleaved Coding*, arXiv:2404.18497v1,6//! 29 April 2024: <https://arxiv.org/abs/2404.18497>. CPU reference reviewed at7//! `jermp/pthash`, phobic revision `e626b424f04fb93a4049cf5e66ebe08734feab2b`.8//! See `phobic-NOTICE` for its MIT license and provenance.9//!10//! This implementation retains PHOBIC's essential components: small independent11//! partitions, the optimized perturbed beta bucket distribution, descending-size12//! bucket placement using seeds p=s*m+d, and one separately bit-packed Compact13//! encoder for each bucket position across **all** partitions. It is not an14//! ordinary hash table. Every original key is independently rehashed and the15//! compressed representation verified collision-free before publication.16//!17//! Fixed source parameters are expected partition size P=256, lambda=4 and18//! epsilon=lambda/(5*sqrt(P))=.05. A frozen Q32 table with 2048 intervals19//! approximates beta_epsilon(x)=x+.95*(1-x)*ln(1-x), with exact integer20//! interpolation. No platform logarithm is evaluated at construction/query.21//! The reference uses floating-point tabulation and other hash functions.22//!23//! Output is a permutation of 0..n for the build keys. Nonmembers may map to24//! arbitrary occupied indices; `Some` does not establish membership. Partition25//! offsets and the 64 column descriptors are retained metadata, not compressed26//! as in the paper. Stable payload contains only the truly bit-packed seeds.27//! Whole-block minima, retained metadata and workspace must be counted when28//! comparing this representation to the paper's succinct implementation.2930const SOURCE_POLICY: [u8; 32] = cdk_rsx_source_policy::source_policy!("phobic.rs");3132use crate::hash::{XXH64_POLICY, Xxh64Word, xxh64};33use crate::{Collection, CollectionId, Error, FixedKey, NODE_BYTES, Result, Storage, Workspace};34use cdk_rsx_engine_nyxus::{Nyxus, NyxusData};35use core::marker::PhantomData;3637type RetainedVec<T> = std::vec::Vec<T, Nyxus>;38const EXPECTED_PARTITION: usize = 256;39const BUCKETS: usize = 64;40const BUCKET_DOMAIN: u64 = 0x7fb2_4e91_01ce_664d;41const PLACEMENT_DOMAIN: u64 = 0xd140_9e57_8e16_aa4b;4243/// Include this policy and the concrete key contract in owning admission.44pub const PHOBIC_POLICY: [u8; 32] = crate::contract(45 "MinimaPHOBIC/P256-lambda4-epsilon0.05/Q32-beta2048/interleaved-Compact/v1",46 &[],47 &[SOURCE_POLICY, crate::MINIMA_POLICY, XXH64_POLICY],48);4950#[derive(Clone, Copy, Debug)]51pub struct PhobicBuildConfig {52 pub max_entries: usize,53 pub max_partitions: u32,54 pub max_partition_entries: u32,55 /// Exclusive upper bound on the pilot p=s*m+d considered per bucket.56 pub max_pilot: u32,57 /// Total candidate key checks, including salted-coordinate construction.58 pub max_key_checks: u64,59 /// Admitted extra vector backing upper bound: 17*n + 8*64*partitions +60 /// 8*(partitions+1) + 5*max_partition_entries. Excludes input Vec,61 /// allocator overhead, fixed stack and the node workspace. Includes the62 /// retained prefix backing while it is copied from transient scratch.63 pub max_work_bytes: usize,64 pub seed: u64,65}66impl Default for PhobicBuildConfig {67 fn default() -> Self {68 Self {69 max_entries: 1_048_576,70 max_partitions: 4096,71 max_partition_entries: 1024,72 max_pilot: 1_048_576,73 max_key_checks: 256 * 1024 * 1024,74 max_work_bytes: 64 * 1024 * 1024,75 seed: 0x7068_6f62_6963_3234,76 }77 }78}79#[derive(Clone, Debug, PartialEq, Eq)]80pub enum PhobicBuildError {81 InvalidConfig,82 Capacity,83 WorkLimit,84 DuplicateKey,85 /// Canonical distinct keys share the placement hash. This hash family86 /// cannot separate them; reject rather than publish a collision.87 HashCollision,88 PilotExhausted {89 partition: u32,90 bucket: u8,91 },92 Storage(Error),93}94impl From<Error> for PhobicBuildError {95 fn from(error: Error) -> Self {96 Self::Storage(error)97 }98}99impl core::fmt::Display for PhobicBuildError {100 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {101 write!(f, "{self:?}")102 }103}104impl std::error::Error for PhobicBuildError {}105pub type PhobicBuildResult<T> = core::result::Result<T, PhobicBuildError>;106107#[derive(Clone, Copy, Debug, PartialEq, Eq)]108pub struct PhobicBuildStats {109 pub entries: u64,110 pub partitions: u32,111 pub max_partition_entries: u32,112 pub seed_bits: u64,113 pub seed_bytes: u64,114 pub raw_seed_bytes: u64,115 pub retained_prefix_bytes: usize,116 pub column_metadata_bytes: usize,117 pub key_checks: u64,118 pub work_bytes: usize,119}120#[repr(C)]121#[derive(Clone, Copy, Default)]122struct Column {123 bit_offset: u64,124 width: u8,125}126#[repr(C)]127#[derive(Clone, Copy)]128struct Entry {129 base: u64,130 partition: u32,131 bucket: u32,132}133const _: () = assert!(core::mem::size_of::<Entry>() == 16);134135/// Move-only Nyxus descriptor; original keys and construction vectors are not136/// retained. Seeds are compressed stable payload; offsets are retained data.137#[repr(C)]138pub struct FrozenPhobic<K: FixedKey> {139 collection: Collection,140 offsets: RetainedVec<u32>,141 columns: [Column; BUCKETS],142 seed: u64,143 seed_bits: u64,144 key_checks: u64,145 work_bytes: usize,146 entries: u32,147 partitions: u32,148 max_partition_entries: u32,149 key: PhantomData<fn() -> K>,150}151// SAFETY: Collection and the Nyxus prefix Vec contain the complete ownership.152// Columns and other fields are inline data; no K/provider/loan is persisted.153unsafe impl<K: FixedKey> NyxusData for FrozenPhobic<K> {154 const __NYXUS_POLICY: [u8; 32] = Self::CONTRACT;155}156157impl<K: FixedKey> FrozenPhobic<K> {158 pub const CONTRACT: [u8; 32] = crate::contract(159 "MinimaFrozenPhobic/FixedKey/v1",160 &[],161 &[PHOBIC_POLICY, K::CONTRACT],162 );163164 /// Consume the complete static key set. Reject duplicates and every finite165 /// limit before publication. No geometry growth or unbounded seed retry.166 /// A provider write failure traps and relies on IC rollback.167 pub fn build(168 storage: &mut dyn Storage,169 mut keys: Vec<K>,170 config: PhobicBuildConfig,171 workspace: &mut Workspace,172 ) -> PhobicBuildResult<Self> {173 const {174 assert!(K::WIDTH <= NODE_BYTES, "PHOBIC key exceeds workspace");175 }176 if config.max_pilot == 0177 || config.max_partition_entries == 0178 || config.max_partition_entries > 65536179 {180 return Err(PhobicBuildError::InvalidConfig);181 }182 if keys.len() > config.max_entries || keys.len() > u32::MAX as usize {183 return Err(PhobicBuildError::Capacity);184 }185 let partitions = keys.len().div_ceil(EXPECTED_PARTITION) as u32;186 if partitions > config.max_partitions {187 return Err(PhobicBuildError::Capacity);188 }189 let work_bytes = work_bytes(keys.len(), partitions, config.max_partition_entries)?;190 if work_bytes > config.max_work_bytes {191 return Err(PhobicBuildError::WorkLimit);192 }193 keys.sort_unstable();194 if keys.windows(2).any(|pair| pair[0] == pair[1]) {195 return Err(PhobicBuildError::DuplicateKey);196 }197 let mut records = reserved(keys.len())?;198 for key in &keys {199 records.push(hash_entry(key, config.seed, partitions, workspace));200 }201 records.sort_unstable_by_key(|entry| entry.base);202 if records.windows(2).any(|pair| pair[0].base == pair[1].base) {203 return Err(PhobicBuildError::HashCollision);204 }205 records.sort_unstable_by_key(|entry| (entry.partition, entry.bucket, entry.base));206 let mut prefix = zeroed(partitions as usize + 1, 0u32)?;207 for record in &records {208 prefix[record.partition as usize + 1] += 1;209 }210 let mut largest = 0;211 for partition in 0..partitions as usize {212 let count = prefix[partition + 1];213 largest = largest.max(count);214 if count > config.max_partition_entries {215 return Err(PhobicBuildError::Capacity);216 }217 prefix[partition + 1] += prefix[partition];218 }219 let mut seeds = zeroed(partitions as usize * BUCKETS, 0u32)?;220 let mut occupied = zeroed(largest as usize, 0u8)?;221 let mut positions = reserved::<u32>(largest as usize)?;222 let mut checks = 0;223 for partition in 0..partitions {224 let slice = &records225 [prefix[partition as usize] as usize..prefix[partition as usize + 1] as usize];226 let size = slice.len() as u32;227 if size == 0 {228 continue;229 }230 occupied[..size as usize].fill(0);231 let mut boundaries = [0usize; BUCKETS + 1];232 for record in slice {233 boundaries[record.bucket as usize + 1] += 1;234 }235 for i in 1..=BUCKETS {236 boundaries[i] += boundaries[i - 1];237 }238 let mut order = core::array::from_fn::<_, BUCKETS, _>(|i| i);239 order.sort_unstable_by_key(|&bucket| {240 (241 core::cmp::Reverse(boundaries[bucket + 1] - boundaries[bucket]),242 bucket,243 )244 });245 let mut next_free = 0;246 for bucket in order {247 let bucket_keys = &slice[boundaries[bucket]..boundaries[bucket + 1]];248 if bucket_keys.is_empty() {249 continue;250 }251 let pilot = find_pilot(252 bucket_keys,253 size,254 &mut occupied[..size as usize],255 &mut positions,256 &mut next_free,257 config,258 &mut checks,259 )260 .ok_or(PhobicBuildError::PilotExhausted {261 partition,262 bucket: bucket as u8,263 })??;264 seeds[bucket * partitions as usize + partition as usize] = pilot;265 }266 }267 let mut columns = [Column::default(); BUCKETS];268 let mut seed_bits = 0u64;269 for (bucket, column) in columns.iter_mut().enumerate() {270 let maximum = seeds[bucket * partitions as usize..(bucket + 1) * partitions as usize]271 .iter()272 .copied()273 .max()274 .unwrap_or(0);275 let width = (32 - maximum.leading_zeros()) as u8;276 *column = Column {277 bit_offset: seed_bits,278 width,279 };280 seed_bits += u64::from(width) * u64::from(partitions);281 }282 let mut encoded = zeroed(seed_bits.div_ceil(8) as usize, 0u8)?;283 for (bucket, column) in columns.iter().enumerate() {284 for partition in 0..partitions {285 pack(286 &mut encoded,287 column.bit_offset + u64::from(partition) * u64::from(column.width),288 column.width,289 seeds[bucket * partitions as usize + partition as usize],290 );291 }292 }293 // Verify the actual compressed stream, independently re-encoding every294 // original key, not just trusting raw-seed placement bookkeeping.295 let mut seen = zeroed(keys.len(), 0u8)?;296 for key in &keys {297 let entry = hash_entry(key, config.seed, partitions, workspace);298 let size = prefix[entry.partition as usize + 1] - prefix[entry.partition as usize];299 let column = columns[entry.bucket as usize];300 let pilot = unpack(301 &encoded,302 column.bit_offset + u64::from(entry.partition) * u64::from(column.width),303 column.width,304 );305 let index = prefix[entry.partition as usize] + position(entry.base, pilot, size);306 assert_eq!(seen[index as usize], 0, "PHOBIC compressed index collision");307 seen[index as usize] = 1;308 }309 let mut offsets = RetainedVec::new_in(Nyxus);310 offsets311 .try_reserve_exact(prefix.len())312 .map_err(|_| PhobicBuildError::WorkLimit)?;313 offsets.extend_from_slice(&prefix);314 let mut collection = Collection::new(storage)?;315 collection.ensure_nodes(storage, (encoded.len() as u64).div_ceil(NODE_BYTES as u64))?;316 // The verified stream already has its final byte representation. The317 // owner splits physical block crossings and leaves its zeroed tail.318 collection319 .write_at(storage, 0, &encoded)320 .unwrap_or_else(|error| panic!("PHOBIC stable write failed: {error}"));321 Ok(Self {322 collection,323 offsets,324 columns,325 seed: config.seed,326 seed_bits,327 key_checks: checks,328 work_bytes,329 entries: keys.len() as u32,330 partitions,331 max_partition_entries: largest,332 key: PhantomData,333 })334 }335336 pub fn replace(337 &mut self,338 storage: &mut dyn Storage,339 keys: Vec<K>,340 config: PhobicBuildConfig,341 workspace: &mut Workspace,342 ) -> PhobicBuildResult<()> {343 self.collection.validate(storage)?;344 *self = Self::build(storage, keys, config, workspace)?;345 Ok(())346 }347 /// Minimal collision-free index for build keys. `None` means the selected348 /// partition is empty. `Some` is NOT membership evidence for unknown keys.349 /// Fetches at most five encoded bytes, with no stable header or cache.350 pub fn index(351 &self,352 storage: &dyn Storage,353 key: &K,354 workspace: &mut Workspace,355 ) -> Result<Option<u64>> {356 if self.entries == 0 {357 self.collection.validate(storage)?;358 return Ok(None);359 }360 let entry = hash_entry(key, self.seed, self.partitions, workspace);361 let low = self.offsets[entry.partition as usize];362 let size = self.offsets[entry.partition as usize + 1] - low;363 if size == 0 {364 self.collection.validate(storage)?;365 return Ok(None);366 }367 let column = self.columns[entry.bucket as usize];368 let bit = column.bit_offset + u64::from(entry.partition) * u64::from(column.width);369 let pilot = if column.width == 0 {370 self.collection.validate(storage)?;371 0372 } else {373 let count = ((bit % 8 + u64::from(column.width)).div_ceil(8)) as usize;374 let bytes = &mut workspace.bytes_mut()[..count];375 let first = count.min(NODE_BYTES - (bit / 8 % NODE_BYTES as u64) as usize);376 self.collection377 .read_at(storage, bit / 8, &mut bytes[..first])?;378 if first < count {379 self.collection380 .read_at(storage, bit / 8 + first as u64, &mut bytes[first..])?;381 }382 unpack(bytes, bit % 8, column.width)383 };384 Ok(Some(u64::from(low + position(entry.base, pilot, size))))385 }386 pub const fn len(&self) -> u64 {387 self.entries as u64388 }389 pub const fn is_empty(&self) -> bool {390 self.entries == 0391 }392 pub const fn seed(&self) -> u64 {393 self.seed394 }395 pub const fn identity(&self) -> CollectionId {396 self.collection.identity()397 }398 pub fn block_count(&self) -> usize {399 self.collection.block_count()400 }401 pub const fn seed_bytes(&self) -> u64 {402 self.seed_bits.div_ceil(8)403 }404 pub fn stats(&self) -> PhobicBuildStats {405 PhobicBuildStats {406 entries: self.len(),407 partitions: self.partitions,408 max_partition_entries: self.max_partition_entries,409 seed_bits: self.seed_bits,410 seed_bytes: self.seed_bytes(),411 raw_seed_bytes: u64::from(self.partitions) * BUCKETS as u64 * 4,412 retained_prefix_bytes: self.offsets.capacity() * 4,413 column_metadata_bytes: core::mem::size_of_val(&self.columns),414 key_checks: self.key_checks,415 work_bytes: self.work_bytes,416 }417 }418}419fn work_bytes(entries: usize, partitions: u32, max_partition: u32) -> PhobicBuildResult<usize> {420 entries421 .checked_mul(17)422 .and_then(|n| n.checked_add(partitions as usize * BUCKETS * 8))423 .and_then(|n| n.checked_add((partitions as usize + 1) * 8))424 .and_then(|n| n.checked_add(max_partition as usize * 5))425 .ok_or(PhobicBuildError::WorkLimit)426}427fn reserved<T>(len: usize) -> PhobicBuildResult<Vec<T>> {428 let mut out = Vec::new();429 out.try_reserve_exact(len)430 .map_err(|_| PhobicBuildError::WorkLimit)?;431 Ok(out)432}433fn zeroed<T: Copy>(len: usize, value: T) -> PhobicBuildResult<Vec<T>> {434 let mut out = reserved(len)?;435 out.resize(len, value);436 Ok(out)437}438fn hash_entry<K: FixedKey>(439 key: &K,440 seed: u64,441 partitions: u32,442 workspace: &mut Workspace,443) -> Entry {444 let bytes = &mut workspace.bytes_mut()[..K::WIDTH];445 key.encode(bytes);446 let seeds = [seed ^ PLACEMENT_DOMAIN, seed, seed ^ BUCKET_DOMAIN];447 let [base, partition_hash, bucket_hash] = if K::WIDTH == 8 {448 let hash = Xxh64Word::new(u64::from_le_bytes((&*bytes).try_into().unwrap()));449 seeds.map(|seed| hash.hash(seed))450 } else {451 seeds.map(|seed| xxh64(bytes, seed))452 };453 Entry {454 base,455 partition: ((u128::from(partition_hash) * u128::from(partitions)) >> 64) as u32,456 bucket: bucket(bucket_hash),457 }458}459fn bucket(hash: u64) -> u32 {460 let x = (hash >> 32) as u32;461 let knot = (x >> 21) as usize;462 let fraction = u64::from(x & ((1 << 21) - 1));463 let low = u64::from(BETA_Q32[knot]);464 let high = u64::from(BETA_Q32[knot + 1]);465 let y = low + ((high - low) * fraction >> 21);466 ((y * BUCKETS as u64) >> 32) as u32467}468fn mixed(mut x: u64) -> u64 {469 x = (x ^ (x >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);470 x = (x ^ (x >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);471 x ^ (x >> 31)472}473fn initial(base: u64, salt: u32, size: u32) -> u32 {474 ((u128::from(mixed(base.wrapping_add(u64::from(salt)))) * u128::from(size)) >> 64) as u32475}476fn position(base: u64, pilot: u32, size: u32) -> u32 {477 (initial(base, pilot / size, size) + pilot % size) % size478}479fn charge(checks: &mut u64, limit: u64) -> PhobicBuildResult<()> {480 if *checks == limit {481 return Err(PhobicBuildError::WorkLimit);482 }483 *checks += 1;484 Ok(())485}486fn find_pilot(487 keys: &[Entry],488 size: u32,489 occupied: &mut [u8],490 positions: &mut Vec<u32>,491 next_free: &mut usize,492 config: PhobicBuildConfig,493 checks: &mut u64,494) -> Option<PhobicBuildResult<u32>> {495 if keys.len() == 1 {496 if let Err(error) = charge(checks, config.max_key_checks) {497 return Some(Err(error));498 }499 while occupied[*next_free] != 0 {500 *next_free += 1;501 }502 let first = initial(keys[0].base, 0, size);503 let displacement = (*next_free as u32 + size - first) % size;504 if displacement >= config.max_pilot {505 return None;506 }507 occupied[*next_free] = 1;508 return Some(Ok(displacement));509 }510 for salt in 0..=(config.max_pilot - 1) / size {511 positions.clear();512 for key in keys {513 if let Err(error) = charge(checks, config.max_key_checks) {514 return Some(Err(error));515 }516 positions.push(initial(key.base, salt, size));517 }518 positions.sort_unstable();519 if positions.windows(2).any(|pair| pair[0] == pair[1]) {520 continue;521 }522 let remaining =523 config.max_pilot - u32::try_from(u64::from(salt) * u64::from(size)).unwrap();524 for displacement in 0..size.min(remaining) {525 let mut clear = true;526 for &base in positions.iter() {527 if let Err(error) = charge(checks, config.max_key_checks) {528 return Some(Err(error));529 }530 if occupied[((base + displacement) % size) as usize] != 0 {531 clear = false;532 break;533 }534 }535 if clear {536 for &base in positions.iter() {537 occupied[((base + displacement) % size) as usize] = 1;538 }539 return Some(Ok(salt * size + displacement));540 }541 }542 }543 None544}545fn pack(out: &mut [u8], bit: u64, width: u8, value: u32) {546 if width == 0 {547 return;548 }549 let shifted = u64::from(value) << (bit % 8);550 let at = (bit / 8) as usize;551 let count = (bit % 8 + u64::from(width)).div_ceil(8) as usize;552 for offset in 0..count {553 out[at + offset] |= (shifted >> (8 * offset)) as u8;554 }555}556fn unpack(bytes: &[u8], bit: u64, width: u8) -> u32 {557 if width == 0 {558 return 0;559 }560 let at = (bit / 8) as usize;561 let count = (bit % 8 + u64::from(width)).div_ceil(8) as usize;562 let mut word = 0u64;563 for offset in 0..count {564 word |= u64::from(bytes[at + offset]) << (8 * offset);565 }566 ((word >> (bit % 8)) & ((1u64 << width) - 1)) as u32567}568569// floor(2^32 * [x + (19/20)*(1-x)*ln(1-x)]) at x=i/2048,570// clamped to u32::MAX at x=1. Generated with Python decimal precision80,571// ROUND_FLOOR. This complete source table is the encoder contract.572const BETA_Q32: [u32; 2049] = [573 0, 105344, 211661, 318952, 427217, 536457, 646673, 757864, 870031, 983174, 1097295, 1212393,574 1328470, 1445524, 1563558, 1682572, 1802565, 1923539, 2045494, 2168430, 2292348, 2417248,575 2543132, 2669999, 2797849, 2926684, 3056504, 3187309, 3319100, 3451877, 3585641, 3720392,576 3856131, 3992858, 4130574, 4269279, 4408974, 4549659, 4691335, 4834002, 4977660, 5122311,577 5267954, 5414591, 5562221, 5710846, 5860465, 6011079, 6162689, 6315295, 6468898, 6623498,578 6779095, 6935691, 7093285, 7251879, 7411472, 7572065, 7733659, 7896254, 8059850, 8224449,579 8390051, 8556655, 8724264, 8892876, 9062494, 9233116, 9404744, 9577378, 9751019, 9925668,580 10101324, 10277988, 10455661, 10634343, 10814035, 10994738, 11176451, 11359175, 11542912,581 11727660, 11913422, 12100197, 12287985, 12476788, 12666607, 12857440, 13049290, 13242156,582 13436039, 13630939, 13826858, 14023795, 14221751, 14420726, 14620722, 14821739, 15023777,583 15226836, 15430917, 15636022, 15842149, 16049301, 16257476, 16466677, 16676903, 16888155,584 17100433, 17313738, 17528071, 17743431, 17959821, 18177239, 18395687, 18615165, 18835674,585 19057214, 19279785, 19503389, 19728026, 19953696, 20180400, 20408138, 20636912, 20866721,586 21097566, 21329447, 21562366, 21796322, 22031316, 22267350, 22504422, 22742534, 22981687,587 23221881, 23463116, 23705393, 23948712, 24193075, 24438481, 24684931, 24932427, 25180967,588 25430553, 25681186, 25932865, 26185592, 26439367, 26694191, 26950064, 27206986, 27464959,589 27723982, 27984057, 28245184, 28507363, 28770595, 29034881, 29300221, 29566615, 29834065,590 30102571, 30372133, 30642751, 30914428, 31187162, 31460955, 31735807, 32011719, 32288691,591 32566724, 32845819, 33125975, 33407194, 33689476, 33972822, 34257232, 34542707, 34829248,592 35116854, 35405527, 35695267, 35986074, 36277950, 36570895, 36864909, 37159993, 37456148,593 37753373, 38051671, 38351041, 38651483, 38952999, 39255589, 39559254, 39863994, 40169809,594 40476701, 40784670, 41093716, 41403841, 41715044, 42027326, 42340688, 42655131, 42970654,595 43287259, 43604947, 43923717, 44243570, 44564508, 44886529, 45209637, 45533829, 45859108,596 46185474, 46512928, 46841470, 47171100, 47501819, 47833629, 48166529, 48500520, 48835602,597 49171777, 49509045, 49847406, 50186862, 50527412, 50869057, 51211798, 51555635, 51900570,598 52246602, 52593733, 52941963, 53291292, 53641721, 53993251, 54345882, 54699615, 55054451,599 55410389, 55767432, 56125579, 56484831, 56845188, 57206652, 57569223, 57932901, 58297687,600 58663582, 59030586, 59398700, 59767924, 60138260, 60509707, 60882267, 61255940, 61630726,601 62006627, 62383643, 62761774, 63141021, 63521385, 63902867, 64285466, 64669184, 65054021,602 65439979, 65827056, 66215255, 66604576, 66995019, 67386585, 67779275, 68173089, 68568028,603 68964093, 69361284, 69759602, 70159047, 70559620, 70961323, 71364154, 71768116, 72173208,604 72579432, 72986788, 73395276, 73804898, 74215653, 74627543, 75040569, 75454730, 75870027,605 76286462, 76704035, 77122746, 77542596, 77963586, 78385716, 78808988, 79233401, 79658957,606 80085655, 80513497, 80942484, 81372615, 81803893, 82236316, 82669887, 83104605, 83540471,607 83977487, 84415652, 84854967, 85295433, 85737051, 86179821, 86623744, 87068821, 87515052,608 87962438, 88410979, 88860677, 89311532, 89763544, 90216715, 90671045, 91126534, 91583184,609 92040995, 92499967, 92960102, 93421400, 93883862, 94347488, 94812279, 95278235, 95745359,610 96213649, 96683107, 97153734, 97625530, 98098496, 98572632, 99047940, 99524419, 100002071,611 100480897, 100960896, 101442071, 101924420, 102407946, 102892648, 103378528, 103865586,612 104353823, 104843240, 105333837, 105825615, 106318574, 106812716, 107308041, 107804550,613 108302243, 108801121, 109301185, 109802436, 110304874, 110808500, 111313315, 111819320,614 112326514, 112834899, 113344476, 113855245, 114367208, 114880363, 115394714, 115910259,615 116427000, 116944938, 117464073, 117984406, 118505938, 119028669, 119552601, 120077733,616 120604067, 121131604, 121660343, 122190286, 122721434, 123253787, 123787346, 124322112,617 124858085, 125395267, 125933657, 126473257, 127014067, 127556089, 128099322, 128643768,618 129189427, 129736300, 130284388, 130833692, 131384212, 131935949, 132488904, 133043077,619 133598470, 134155082, 134712916, 135271971, 135832248, 136393748, 136956472, 137520421,620 138085594, 138651994, 139219621, 139788475, 140358557, 140929869, 141502410, 142076182,621 142651185, 143227420, 143804888, 144383590, 144963526, 145544697, 146127105, 146710749,622 147295630, 147881749, 148469108, 149057706, 149647545, 150238625, 150830947, 151424512,623 152019321, 152615374, 153212672, 153811217, 154411008, 155012046, 155614333, 156217869,624 156822655, 157428691, 158035979, 158644519, 159254312, 159865359, 160477660, 161091217,625 161706030, 162322100, 162939428, 163558015, 164177860, 164798966, 165421333, 166044961,626 166669853, 167296007, 167923426, 168552109, 169182058, 169813274, 170445757, 171079509,627 171714529, 172350819, 172988380, 173627212, 174267316, 174908694, 175551345, 176195271,628 176840472, 177486950, 178134705, 178783737, 179434049, 180085640, 180738511, 181392664,629 182048099, 182704816, 183362817, 184022103, 184682674, 185344532, 186007676, 186672108,630 187337829, 188004839, 188673140, 189342732, 190013616, 190685792, 191359263, 192034028,631 192710088, 193387445, 194066099, 194746050, 195427300, 196109850, 196793701, 197478852,632 198165306, 198853063, 199542124, 200232489, 200924160, 201617138, 202311422, 203007015,633 203703917, 204402129, 205101651, 205802485, 206504631, 207208091, 207912865, 208618954,634 209326359, 210035081, 210745120, 211456478, 212169155, 212883153, 213598471, 214315112,635 215033075, 215752363, 216472975, 217194913, 217918177, 218642768, 219368687, 220095936,636 220824515, 221554424, 222285665, 223018239, 223752146, 224487388, 225223965, 225961879,637 226701129, 227441717, 228183645, 228926912, 229671520, 230417469, 231164761, 231913397,638 232663376, 233414701, 234167372, 234921391, 235676757, 236433472, 237191537, 237950952,639 238711719, 239473839, 240237312, 241002140, 241768322, 242535862, 243304758, 244075012,640 244846625, 245619599, 246393933, 247169628, 247946687, 248725109, 249504896, 250286048,641 251068567, 251852453, 252637708, 253424332, 254212326, 255001691, 255792428, 256584538,642 257378023, 258172882, 258969117, 259766729, 260565719, 261366087, 262167836, 262970965,643 263775475, 264581368, 265388645, 266197306, 267007353, 267818786, 268631606, 269445815,644 270261413, 271078401, 271896781, 272716553, 273537718, 274360277, 275184232, 276009582,645 276836330, 277664476, 278494021, 279324966, 280157312, 280991060, 281826211, 282662766,646 283500726, 284340093, 285180866, 286023047, 286866637, 287711637, 288558048, 289405871,647 290255107, 291105757, 291957822, 292811303, 293666200, 294522516, 295380251, 296239406,648 297099982, 297961980, 298825401, 299690247, 300556517, 301424213, 302293337, 303163889,649 304035869, 304909281, 305784123, 306660398, 307538106, 308417248, 309297826, 310179840,650 311063291, 311948181, 312834511, 313722281, 314611492, 315502147, 316394245, 317287788,651 318182776, 319079211, 319977095, 320876427, 321777209, 322679442, 323583128, 324488266,652 325394859, 326302907, 327212412, 328123373, 329035794, 329949674, 330865014, 331781816,653 332700081, 333619810, 334541004, 335463664, 336387790, 337313385, 338240450, 339168984,654 340098990, 341030469, 341963421, 342897847, 343833750, 344771129, 345709987, 346650323,655 347592140, 348535438, 349480218, 350426481, 351374230, 352323463, 353274184, 354226393,656 355180090, 356135278, 357091957, 358050128, 359009793, 359970953, 360933608, 361897760,657 362863410, 363830559, 364799208, 365769358, 366741011, 367714168, 368688830, 369664997,658 370642671, 371621854, 372602546, 373584748, 374568462, 375553688, 376540429, 377528685,659 378518456, 379509746, 380502553, 381496881, 382492729, 383490099, 384488992, 385489410,660 386491353, 387494823, 388499821, 389506348, 390514404, 391523993, 392535113, 393547768,661 394561957, 395577683, 396594945, 397613747, 398634087, 399655969, 400679393, 401704360,662 402730871, 403758928, 404788531, 405819683, 406852384, 407886635, 408922438, 409959794,663 410998704, 412039169, 413081191, 414124770, 415169909, 416216607, 417264867, 418314689,664 419366075, 420419026, 421473544, 422529629, 423587283, 424646506, 425707301, 426769668,665 427833609, 428899125, 429966217, 431034887, 432105135, 433176963, 434250373, 435325365,666 436401940, 437480101, 438559847, 439641181, 440724104, 441808617, 442894722, 443982418,667 445071709, 446162595, 447255077, 448349157, 449444835, 450542114, 451640995, 452741478,668 453843566, 454947259, 456052558, 457159466, 458267982, 459378110, 460489849, 461603201,669 462718168, 463834751, 464952951, 466072769, 467194207, 468317267, 469441948, 470568253,670 471696184, 472825740, 473956925, 475089738, 476224182, 477360257, 478497966, 479637308,671 480778287, 481920902, 483065156, 484211050, 485358585, 486507762, 487658583, 488811049,672 489965162, 491120923, 492278333, 493437393, 494598106, 495760472, 496924492, 498090169,673 499257503, 500426496, 501597149, 502769464, 503943442, 505119085, 506296393, 507475368,674 508656012, 509838326, 511022311, 512207969, 513395302, 514584309, 515774994, 516967358,675 518161401, 519357125, 520554532, 521753624, 522954400, 524156864, 525361016, 526566858,676 527774391, 528983617, 530194537, 531407153, 532621465, 533837476, 535055187, 536274599,677 537495715, 538718534, 539943059, 541169291, 542397232, 543626883, 544858246, 546091322,678 547326112, 548562618, 549800842, 551040785, 552282448, 553525833, 554770942, 556017776,679 557266336, 558516624, 559768641, 561022389, 562277870, 563535084, 564794034, 566054722,680 567317147, 568581313, 569847220, 571114870, 572384264, 573655405, 574928293, 576202931,681 577479319, 578757459, 580037354, 581319003, 582602410, 583887574, 585174499, 586463186,682 587753635, 589045849, 590339830, 591635578, 592933095, 594232383, 595533444, 596836279,683 598140890, 599447278, 600755445, 602065392, 603377121, 604690634, 606005932, 607323017,684 608641890, 609962553, 611285008, 612609256, 613935299, 615263138, 616592776, 617924213,685 619257452, 620592493, 621929340, 623267992, 624608453, 625950722, 627294804, 628640697,686 629988406, 631337930, 632689273, 634042434, 635397417, 636754223, 638112853, 639473309,687 640835593, 642199706, 643565651, 644933429, 646303041, 647674489, 649047775, 650422901,688 651799868, 653178678, 654559332, 655941833, 657326183, 658712382, 660100433, 661490337,689 662882096, 664275712, 665671186, 667068520, 668467717, 669868777, 671271703, 672676495,690 674083157, 675491690, 676902095, 678314374, 679728529, 681144562, 682562474, 683982268,691 685403945, 686827506, 688252954, 689680291, 691109518, 692540637, 693973650, 695408558,692 696845364, 698284069, 699724675, 701167184, 702611597, 704057918, 705506146, 706956285,693 708408335, 709862300, 711318180, 712775977, 714235694, 715697332, 717160894, 718626380,694 720093793, 721563134, 723034406, 724507611, 725982750, 727459825, 728938838, 730419790,695 731902685, 733387523, 734874307, 736363039, 737853720, 739346352, 740840937, 742337478,696 743835975, 745336432, 746838850, 748343230, 749849575, 751357887, 752868168, 754380419,697 755894643, 757410841, 758929016, 760449169, 761971303, 763495419, 765021519, 766549606,698 768079681, 769611746, 771145804, 772681856, 774219904, 775759950, 777301997, 778846046,699 780392100, 781940159, 783490228, 785042306, 786596397, 788152502, 789710624, 791270765,700 792832926, 794397109, 795963318, 797531553, 799101817, 800674111, 802248439, 803824802,701 805403202, 806983641, 808566121, 810150645, 811737214, 813325831, 814916497, 816509215,702 818103988, 819700816, 821299702, 822900649, 824503658, 826108731, 827715872, 829325081,703 830936361, 832549714, 834165143, 835782649, 837402235, 839023902, 840647654, 842273491,704 843901417, 845531434, 847163543, 848797748, 850434049, 852072450, 853712952, 855355558,705 857000271, 858647091, 860296022, 861947066, 863600224, 865255500, 866912895, 868572412,706 870234053, 871897820, 873563716, 875231743, 876901902, 878574197, 880248630, 881925203,707 883603917, 885284777, 886967783, 888652939, 890340246, 892029706, 893721323, 895415099,708 897111035, 898809135, 900509400, 902211832, 903916436, 905623211, 907332162, 909043290,709 910756598, 912472088, 914189763, 915909624, 917631675, 919355918, 921082355, 922810988,710 924541820, 926274854, 928010092, 929747536, 931487188, 933229052, 934973130, 936719424,711 938467936, 940218669, 941971626, 943726809, 945484220, 947243863, 949005739, 950769851,712 952536201, 954304793, 956075628, 957848709, 959624039, 961401620, 963181455, 964963546,713 966747896, 968534507, 970323382, 972114524, 973907935, 975703618, 977501575, 979301809,714 981104322, 982909118, 984716198, 986525565, 988337223, 990151173, 991967419, 993785962,715 995606806, 997429954, 999255407, 1001083168, 1002913241, 1004745628, 1006580332, 1008417355,716 1010256699, 1012098369, 1013942366, 1015788693, 1017637353, 1019488349, 1021341683, 1023197358,717 1025055377, 1026915743, 1028778458, 1030643526, 1032510948, 1034380728, 1036252869, 1038127372,718 1040004242, 1041883481, 1043765092, 1045649078, 1047535441, 1049424184, 1051315310, 1053208822,719 1055104723, 1057003016, 1058903703, 1060806788, 1062712273, 1064620162, 1066530456, 1068443160,720 1070358276, 1072275806, 1074195755, 1076118124, 1078042916, 1079970136, 1081899785, 1083831867,721 1085766384, 1087703340, 1089642737, 1091584579, 1093528869, 1095475609, 1097424803, 1099376453,722 1101330562, 1103287135, 1105246173, 1107207680, 1109171659, 1111138112, 1113107044, 1115078457,723 1117052354, 1119028738, 1121007612, 1122988980, 1124972845, 1126959209, 1128948077, 1130939450,724 1132933332, 1134929727, 1136928637, 1138930066, 1140934017, 1142940493, 1144949498, 1146961033,725 1148975104, 1150991712, 1153010862, 1155032556, 1157056798, 1159083591, 1161112938, 1163144842,726 1165179307, 1167216337, 1169255934, 1171298101, 1173342842, 1175390161, 1177440061, 1179492544,727 1181547615, 1183605277, 1185665533, 1187728386, 1189793841, 1191861899, 1193932566, 1196005843,728 1198081735, 1200160245, 1202241376, 1204325133, 1206411517, 1208500534, 1210592186, 1212686476,729 1214783409, 1216882988, 1218985216, 1221090097, 1223197634, 1225307832, 1227420692, 1229536220,730 1231654419, 1233775291, 1235898842, 1238025074, 1240153991, 1242285596, 1244419894, 1246556888,731 1248696581, 1250838978, 1252984082, 1255131896, 1257282424, 1259435671, 1261591639, 1263750333,732 1265911755, 1268075911, 1270242804, 1272412436, 1274584813, 1276759938, 1278937815, 1281118448,733 1283301840, 1285487995, 1287676917, 1289868610, 1292063078, 1294260324, 1296460353, 1298663169,734 1300868774, 1303077174, 1305288373, 1307502373, 1309719179, 1311938796, 1314161226, 1316386474,735 1318614545, 1320845441, 1323079167, 1325315727, 1327555125, 1329797366, 1332042452, 1334290389,736 1336541179, 1338794829, 1341051340, 1343310719, 1345572968, 1347838092, 1350106095, 1352376981,737 1354650755, 1356927420, 1359206981, 1361489442, 1363774807, 1366063081, 1368354267, 1370648371,738 1372945395, 1375245345, 1377548225, 1379854040, 1382162792, 1384474488, 1386789130, 1389106724,739 1391427275, 1393750785, 1396077260, 1398406705, 1400739122, 1403074518, 1405412897, 1407754262,740 1410098619, 1412445972, 1414796325, 1417149683, 1419506050, 1421865432, 1424227832, 1426593256,741 1428961707, 1431333191, 1433707712, 1436085274, 1438465883, 1440849543, 1443236258, 1445626034,742 1448018875, 1450414786, 1452813771, 1455215835, 1457620984, 1460029221, 1462440552, 1464854981,743 1467272514, 1469693155, 1472116909, 1474543780, 1476973774, 1479406896, 1481843151, 1484282543,744 1486725077, 1489170759, 1491619593, 1494071584, 1496526738, 1498985059, 1501446553, 1503911224,745 1506379078, 1508850119, 1511324354, 1513801786, 1516282421, 1518766264, 1521253321, 1523743596,746 1526237096, 1528733824, 1531233786, 1533736988, 1536243434, 1538753131, 1541266083, 1543782296,747 1546301775, 1548824525, 1551350552, 1553879862, 1556412459, 1558948348, 1561487537, 1564030029,748 1566575831, 1569124948, 1571677385, 1574233149, 1576792244, 1579354676, 1581920451, 1584489574,749 1587062052, 1589637889, 1592217091, 1594799665, 1597385615, 1599974948, 1602567669, 1605163784,750 1607763298, 1610366219, 1612972551, 1615582300, 1618195473, 1620812074, 1623432111, 1626055588,751 1628682513, 1631312890, 1633946726, 1636584027, 1639224798, 1641869047, 1644516779, 1647168000,752 1649822716, 1652480934, 1655142659, 1657807898, 1660476656, 1663148941, 1665824759, 1668504115,753 1671187016, 1673873469, 1676563479, 1679257053, 1681954198, 1684654919, 1687359224, 1690067119,754 1692778609, 1695493703, 1698212405, 1700934724, 1703660664, 1706390234, 1709123439, 1711860287,755 1714600783, 1717344935, 1720092749, 1722844233, 1725599392, 1728358234, 1731120765, 1733886992,756 1736656923, 1739430564, 1742207921, 1744989003, 1747773815, 1750562366, 1753354661, 1756150708,757 1758950514, 1761754087, 1764561433, 1767372559, 1770187473, 1773006181, 1775828692, 1778655012,758 1781485149, 1784319110, 1787156902, 1789998532, 1792844009, 1795693340, 1798546531, 1801403591,759 1804264528, 1807129347, 1809998058, 1812870668, 1815747184, 1818627615, 1821511967, 1824400249,760 1827292468, 1830188632, 1833088749, 1835992827, 1838900874, 1841812898, 1844728906, 1847648906,761 1850572908, 1853500917, 1856432944, 1859368995, 1862309080, 1865253205, 1868201380, 1871153613,762 1874109911, 1877070284, 1880034739, 1883003285, 1885975931, 1888952684, 1891933554, 1894918549,763 1897907677, 1900900947, 1903898367, 1906899947, 1909905695, 1912915620, 1915929730, 1918948034,764 1921970541, 1924997261, 1928028202, 1931063372, 1934102781, 1937146439, 1940194353, 1943246534,765 1946302990, 1949363730, 1952428764, 1955498101, 1958571751, 1961649722, 1964732024, 1967818667,766 1970909659, 1974005012, 1977104733, 1980208833, 1983317321, 1986430208, 1989547502, 1992669213,767 1995795352, 1998925928, 2002060951, 2005200431, 2008344379, 2011492803, 2014645714, 2017803123,768 2020965039, 2024131473, 2027302435, 2030477935, 2033657983, 2036842591, 2040031768, 2043225526,769 2046423873, 2049626822, 2052834383, 2056046566, 2059263382, 2062484843, 2065710958, 2068941739,770 2072177197, 2075417343, 2078662187, 2081911742, 2085166017, 2088425025, 2091688776, 2094957283,771 2098230555, 2101508605, 2104791445, 2108079085, 2111371537, 2114668813, 2117970925, 2121277885,772 2124589704, 2127906393, 2131227966, 2134554434, 2137885809, 2141222104, 2144563330, 2147909499,773 2151260624, 2154616718, 2157977793, 2161343860, 2164714934, 2168091026, 2171472149, 2174858315,774 2178249539, 2181645831, 2185047207, 2188453677, 2191865256, 2195281957, 2198703792, 2202130775,775 2205562920, 2209000240, 2212442748, 2215890457, 2219343382, 2222801537, 2226264934, 2229733588,776 2233207512, 2236686721, 2240171229, 2243661049, 2247156197, 2250656686, 2254162530, 2257673745,777 2261190344, 2264712342, 2268239754, 2271772595, 2275310879, 2278854622, 2282403838, 2285958542,778 2289518750, 2293084476, 2296655737, 2300232548, 2303814923, 2307402879, 2310996432, 2314595596,779 2318200389, 2321810825, 2325426922, 2329048694, 2332676159, 2336309332, 2339948231, 2343592871,780 2347243268, 2350899441, 2354561405, 2358229178, 2361902776, 2365582217, 2369267517, 2372958694,781 2376655766, 2380358750, 2384067663, 2387782523, 2391503348, 2395230156, 2398962965, 2402701793,782 2406446658, 2410197579, 2413954573, 2417717661, 2421486860, 2425262189, 2429043667, 2432831313,783 2436625146, 2440425186, 2444231452, 2448043964, 2451862740, 2455687801, 2459519167, 2463356858,784 2467200894, 2471051295, 2474908081, 2478771274, 2482640893, 2486516960, 2490399495, 2494288520,785 2498184056, 2502086124, 2505994745, 2509909942, 2513831735, 2517760148, 2521695202, 2525636918,786 2529585321, 2533540431, 2537502272, 2541470867, 2545446238, 2549428409, 2553417403, 2557413243,787 2561415954, 2565425558, 2569442079, 2573465543, 2577495973, 2581533393, 2585577828, 2589629303,788 2593687843, 2597753473, 2601826219, 2605906105, 2609993158, 2614087403, 2618188867, 2622297575,789 2626413555, 2630536832, 2634667434, 2638805388, 2642950721, 2647103460, 2651263632, 2655431267,790 2659606392, 2663789034, 2667979223, 2672176988, 2676382357, 2680595359, 2684816023, 2689044380,791 2693280459, 2697524290, 2701775904, 2706035331, 2710302601, 2714577746, 2718860797, 2723151785,792 2727450743, 2731757701, 2736072694, 2740395752, 2744726909, 2749066198, 2753413652, 2757769304,793 2762133190, 2766505342, 2770885795, 2775274585, 2779671745, 2784077312, 2788491321, 2792913808,794 2797344808, 2801784360, 2806232498, 2810689262, 2815154688, 2819628813, 2824111677, 2828603318,795 2833103774, 2837613085, 2842131290, 2846658428, 2851194542, 2855739670, 2860293854, 2864857136,796 2869429556, 2874011158, 2878601983, 2883202074, 2887811476, 2892430231, 2897058384, 2901695979,797 2906343061, 2910999675, 2915665868, 2920341686, 2925027175, 2929722382, 2934427356, 2939142144,798 2943866795, 2948601358, 2953345882, 2958100418, 2962865016, 2967639727, 2972424603, 2977219696,799 2982025059, 2986840744, 2991666806, 2996503299, 3001350278, 3006207798, 3011075915, 3015954687,800 3020844170, 3025744422, 3030655501, 3035577468, 3040510381, 3045454302, 3050409291, 3055375410,801 3060352721, 3065341289, 3070341177, 3075352449, 3080375171, 3085409410, 3090455232, 3095512704,802 3100581896, 3105662877, 3110755717, 3115860487, 3120977258, 3126106105, 3131247099, 3136400316,803 3141565832, 3146743722, 3151934063, 3157136936, 3162352417, 3167580589, 3172821531, 3178075328,804 3183342061, 3188621816, 3193914678, 3199220735, 3204540073, 3209872783, 3215218954, 3220578678,805 3225952049, 3231339159, 3236740105, 3242154983, 3247583892, 3253026930, 3258484199, 3263955801,806 3269441841, 3274942422, 3280457654, 3285987643, 3291532500, 3297092336, 3302667266, 3308257405,807 3313862869, 3319483777, 3325120251, 3330772412, 3336440385, 3342124296, 3347824274, 3353540451,808 3359272957, 3365021929, 3370787504, 3376569821, 3382369022, 3388185251, 3394018655, 3399869384,809 3405737590, 3411623426, 3417527052, 3423448626, 3429388312, 3435346276, 3441322688, 3447317719,810 3453331546, 3459364348, 3465416306, 3471487608, 3477578442, 3483689002, 3489819485, 3495970093,811 3502141031, 3508332508, 3514544739, 3520777942, 3527032339, 3533308160, 3539605636, 3545925006,812 3552266514, 3558630407, 3565016940, 3571426374, 3577858974, 3584315014, 3590794772, 3597298534,813 3603826593, 3610379249, 3616956809, 3623559589, 3630187912, 3636842109, 3643522522, 3650229499,814 3656963400, 3663724594, 3670513459, 3677330385, 3684175774, 3691050038, 3697953602, 3704886902,815 3711850389, 3718844529, 3725869799, 3732926694, 3740015725, 3747137418, 3754292317, 3761480985,816 3768704005, 3775961979, 3783255532, 3790585310, 3797951985, 3805356253, 3812798836, 3820280486,817 3827801985, 3835364146, 3842967816, 3850613878, 3858303255, 3866036908, 3873815845, 3881641118,818 3889513832, 3897435142, 3905406266, 3913428479, 3921503127, 3929631628, 3937815477, 3946056256,819 3954355641, 3962715408, 3971137444, 3979623759, 3988176496, 3996797946, 4005490565, 4014256990,820 4023100060, 4032022843, 4041028662, 4050121130, 4059304189, 4068582154, 4077959776, 4087442303,821 4097035571, 4106746100, 4116581229, 4126549276, 4136659750, 4146923630, 4157353727, 4167965192,822 4178776220, 4189809072, 4201091613, 4212659743, 4224561478, 4236864371, 4249670660, 4263153927,823 4277679658, 4294967295,824];825826#[cfg(test)]827#[path = "phobic_tests.rs"]828mod tests;