/** * Hash Utilities * * Common hashing functions for consistent data distribution and rollouts. * * @fileoverview Hash utility functions * @version 1.0.0 */ /** * Optimized string hashing function for consistent distribution. * Uses FNV-1a hash algorithm for better distribution and performance. * FNV-1a provides excellent avalanche properties and is faster than * polynomial rolling hash for short to medium strings. * * @param str - String to hash * @returns Positive hash value * * @example * ```typescript * const hash = hashString('user123:AUTH_GOOGLE'); * const bucket = hash % 100; // 0-99 * ``` * * @remarks * FNV-1a algorithm benefits: * - Excellent distribution for hash tables * - Fast computation with minimal operations * - Good avalanche effect (small input changes create large output changes) * - Consistent timing reduces timing attack vulnerabilities */ export declare function hashString(str: string): number; /** * Determines if a user should be included in a rollout based on percentage. * Uses consistent hashing to ensure the same user always gets the same result. * * @param identifier - Unique identifier for consistency (e.g., userId, flagKey) * @param percentage - Rollout percentage (0-100) * @returns true if identifier should be included in rollout * * @example * ```typescript * const shouldInclude = isInRollout('user123:AUTH_GOOGLE', 25); // 25% rollout * ``` */ export declare function isInRollout(identifier: string, percentage: number): boolean; /** * Creates a consistent rollout identifier for a user and feature. * * @param featureKey - Feature or flag key * @param userId - User identifier (defaults to 'anonymous') * @returns Consistent identifier for rollout calculations * * @example * ```typescript * const identifier = createRolloutIdentifier('AUTH_GOOGLE', 'user123'); * const inRollout = isInRollout(identifier, 50); * ``` */ export declare function createRolloutIdentifier(featureKey: string, userId?: string): string; /** * Hash-based utilities for consistent data operations. */ export declare const HashUtils: { /** * Generates a hash-based bucket for load balancing or distribution. * * @param identifier - Unique identifier * @param bucketCount - Number of buckets (default: 10) * @returns Bucket number (0 to bucketCount-1) */ readonly getBucket: (identifier: string, bucketCount?: number) => number; /** * Checks if an identifier falls within a specific bucket range. * * @param identifier - Unique identifier * @param startBucket - Starting bucket (inclusive) * @param endBucket - Ending bucket (inclusive) * @param totalBuckets - Total number of buckets (default: 100) * @returns true if identifier is in the bucket range */ readonly isInBucketRange: (identifier: string, startBucket: number, endBucket: number, totalBuckets?: number) => boolean; /** * Creates a deterministic random seed from a string. * Uses the improved hash function and ensures the seed is within * the safe range for JavaScript's Math.random seeding. * * @param str - String to convert to seed * @returns Deterministic seed value (0 to 2^31-1) */ readonly createSeed: (str: string) => number; }; //# sourceMappingURL=hash.d.ts.map