FairHash: A Fair and Memory/Time-efficient Hashmap

Nima Shahbazi, Stavros Sintos, Abolfazl Asudeh · DOI

Abstract: Hashmaps are fundamental to data processing, yet their design has traditionally prioritized performance over social equity. This paper introduces FairHash, a novel hashmap framework that guarantees group fairness by ensuring hash collisions are distributed uniformly across demographic groups. By framing fair hashing as a variant of the "necklace splitting" problem, we prove that perfectly fair partitions always exist. Our evaluation across four large-scale datasets shows that FairHash achieves zero unfairness with logarithmic query times and minimal memory overhead, bridging the gap between efficient data structures and algorithmic fairness.

Introduction

Hashmaps are a foundational building block in computer science, utilized in everything from database joins to security filters. Traditionally, hashmap research focuses on a singular goal: minimizing collisions to maximize lookup speed. Recently, "learned" or data-dependent hashmaps have emerged, leveraging underlying data distributions to create perfectly balanced buckets.

However, these techniques ignore group fairness. In sensitive applications—such as airline security "no-fly" lists—hashmap collisions result in false positives. If these collisions occur more frequently for one demographic group (e.g., based on gender or race), that group faces a disproportionate burden of "extra screening" or invalid results. FairHash addresses this "fairness gap" in data structure design, ensuring that the burden of collisions is shared equally across all groups.

The FairHash Framework

The authors introduce FairHash, a framework comprising three distinct algorithmic families that balance the trade-offs between perfect fairness, memory usage, and computational complexity:

  1. Ranking-based Algorithms: These identify a "ranking function" (a linear projection of the data) that minimizes unfairness. They are highly memory-efficient, requiring no more storage than a standard data-dependent hashmap.
  2. Cut-based Algorithms: These guarantee zero unfairness regardless of the data distribution.
  3. Sweep&Cut: A greedy approach that sweeps through the data to create bins.
  4. Necklace Splitting: This method makes a clever theoretical connection to the combinatorial "necklace splitting problem." By treating demographic groups as different types of beads on a necklace, the authors use topological results to find the minimum number of "cuts" needed to ensure every hash bucket receives an exactly proportional share of each group.
  5. Discrepancy-based Algorithms: These utilize dynamic programming or local search heuristics to allow for slight "discrepancies" in bucket sizes, further optimizing for memory or specific fairness constraints.

Theoretical Foundations

A key contribution of this work is the formalization of Pairwise Fairness. This requirement demands that the ratio of different groups is equal across all buckets, ensuring that the probability of two members of the same group colliding is identical to the global collision rate. By reducing fair hashing to the necklace splitting problem, the authors prove that a fair hashmap always exists, regardless of how skewed or "clumped" the input data may be. Furthermore, the algorithms are designed for Pareto-Optimality, ensuring that fairness does not degrade the hashmap's performance for any individual group compared to the global average.

Experimental Evaluation

The researchers evaluated FairHash using four large-scale datasets commonly used in fairness literature:

  • Adult: Census data (protected attribute: sex).
  • Compas: Criminal defendant records (protected attributes: sex, race).
  • Diabetes: Hospitalization records (protected attribute: sex).
  • ChicagoPop: A 1-million-entry semi-synthetic dataset simulating the population of Chicago (protected attribute: race).

Results and Discussion

Achieving Zero Unfairness

The experiments demonstrate that FairHash effectively eliminates group bias. While standard CDF-based hashmaps often result in buckets dominated by a single demographic, FairHash maintains consistent group ratios.

Visual comparison of hashmap distributions: (Left) Input distribution; (Middle) CDF-based hashmap showing imbalance; (Right) FairHash achieving perfectly equal group ratios.

Performance and Complexity

Despite the added fairness constraints, FairHash maintains high efficiency. Query times remain logarithmic ($O(\log m)$), matching the performance of state-of-the-art data-dependent hashmaps. While the "Necklace Splitting" approach requires more boundaries (cuts) than a standard hashmap, it typically only requires about twice as many, representing a minimal memory trade-off for guaranteed fairness.

Summary of algorithmic performance, complexity, and fairness guarantees.

Conclusion and Future Work

FairHash proves that algorithmic bias can be addressed at the data structure level without sacrificing performance. However, challenges remain. The complexity of cut-based methods increases as the number of demographic groups grows, and current ranking functions are limited to linear projections. Future research will explore non-linear functions for high-dimensional data and extend the framework to dynamic settings where data is frequently inserted or deleted.

Summary updated

Abstract

Hashmap is a fundamental data structure in computer science. There has been extensive research on constructing hashmaps that minimize the number of collisions leading to efficient lookup query time. Recently, the data-dependant approaches, construct hashmaps tailored for a target data distribution that guarantee to uniformly distribute data across different buckets and hence minimize the collisions. Still, to the best of our knowledge, none of the existing technique guarantees group fairness among different groups of items stored in the hashmap.Therefore, in this paper, we introduce FairHash, a data-dependant hashmap that guarantees uniform distribution at the group-level across hash buckets, and hence, satisfies the statistical parity notion of group fairness. We formally define, three notions of fairness and, unlike existing work, FairHash satisfies all three of them simultaneously. We propose three families of algorithms to design fair hashmaps, suitable for different settings. Our ranking-based algorithms reduce the unfairness of data-dependant hashmaps without any memory-overhead. The cut-based algorithms guarantee zero-unfairness in all cases, irrespective of how the data is distributed, but those introduce an extra memory-overhead. Last but not least, the discrepancy-based algorithms enable trading off between various fairness notions. In addition to the theoretical analysis, we perform extensive experiments to evaluate the efficiency and efficacy of our algorithms on real datasets. Our results verify the superiority of FairHash compared to the other baselines on fairness at almost no performance cost.
BibTeX
@article{shahbazi2024fairhash,
  author = {Nima Shahbazi and Stavros Sintos and Abolfazl Asudeh},
  title = {{FairHash: A Fair and Memory/Time-efficient Hashmap}},
  journal = {Proc. ACM Manag. Data},
  year = {2024},
  doi = {10.1145/3654939},
}
Figure