promotional bannermobile promotional banner

LibBucketedHashSet

Bucketed Hash Set implementation for WoW Lua 5.1 environment - Alternative to Merkle trees for divergence detection and set reconciliation.

LibBucketedHashSet

Bucketed Hash Set for WoW Lua 5.1 environment - Alternative to Merkle trees for divergence detection and set reconciliation.

Features

  • Efficiently detects divergence between sets.
  • Fast toggle operation: toggling the same value twice removes it.
  • Low memory usage, suitable for constrained environments.
  • Simple API for toggling and checking elements.
  • Compatible with World of Warcraft Lua 5.1 environment.

Installation

To install LibBucketedHashSet, simply download the LibBucketedHashSet.lua file and include it in your WoW addon folder. Then, you can load it using LibStub in your addon code.

local LibBucketedHashSet = LibStub("LibBucketedHashSet")

Usage

-- Create a new Bucketed Hash Set with 32 buckets
local set = LibBucketedHashSet.New(32)

-- Add any values to the set
for i = 1, 1000 do
    set:Update("value" .. i)
end

-- Remove existing values from the set
for i = 500, 750 do
    set:Update("value" .. i) -- Updating the same value removes it
end

-- Bucket index of a value must be stored when inserting it
local valueBucketIndexMap = {}
valueBucketIndexMap["someValue"] = set:Update("someValue")

-- Comparing two bucketed hash sets
local setA = LibBucketedHashSet.New(32)
local setB = LibBucketedHashSet.New(32)
setA:Update("foo")
setB:Update("foo")
assert(setA == setB, "Sets should be equal")
setB:Update("bar")
assert(setA ~= setB, "Sets should not be equal")

-- Check which buckets differ between two sets
for i = 1, setA.numBuckets do
    if setA.buckets[i] ~= setB.buckets[i] then
        print("Bucket " .. i .. " differs between the two sets.")
    end
end

-- Export the bucketed hash set state for serialization
local state = setA:Export()

-- Import the state into a new bucketed hash set
local setC = LibBucketedHashSet.Import(state)

API

LibBucketedHashSet.New(numBuckets, seed)

Create a new Bucketed Hash Set instance.

  • numBuckets: Number of buckets in the bucketedHashSet.
  • seed: Optional seed for hash function (default: 0).
  • Returns: The new Bucketed Hash Set instance.

bucketedHashSet:Update(value, …)

Update a value in the bucketed hash set. Updating the same value twice removes it. Only the first value is used to determine the bucket index, but additional values can be included in the hash.

  • value: Value to update.
  • ...: Additional values to include in the hash (optional).

bucketedHashSet:Clear()

Clear all values from the bucketedHashSet.

bucketedHashSet:Export()

Export the current state of the bucketedHashSet.

  • Returns: Compact representation of the bucketedHashSet.

LibBucketedHashSet.Import(state)

Import a new Bucketed Hash Set from a compact representation.

  • state: Compact representation of the bucketedHashSet.
  • Returns: The imported Bucketed Hash Set instance.

License

This library is released under the MIT License. See the LICENSE file for details.

The LibBucketedHashSet Team

profile avatar
  • 8
    Projects
  • 31.8K
    Downloads

More from ErunehtarView all

  • Hardcore Mode project image

    Hardcore Mode

    • 882
    • Addons

    Adds hardcore mode to non-hardcore realms

    • 882
    • April 14, 2026
    • Addons
  • LibP2PDB project image

    LibP2PDB

    • 198
    • Addons

    A lightweight, embeddable library for peer-to-peer distributed-database synchronization in WoW addons.

    • 198
    • April 14, 2026
    • Addons
    • +1
  • LibBloomFilter project image

    LibBloomFilter

    • 84
    • Addons

    Bloom Filter implementation for WoW Lua 5.1 environment

    • 84
    • February 26, 2026
    • Addons
    • +1
  • LibPatternedBloomFilter project image

    LibPatternedBloomFilter

    • 94
    • Addons

    Patterned Bloom Filter implementation for WoW Lua 5.1 environment

    • 94
    • February 16, 2026
    • Addons
    • +1
  • Hardcore Mode project image

    Hardcore Mode

    • 882
    • Addons

    Adds hardcore mode to non-hardcore realms

    • 882
    • April 14, 2026
    • Addons
  • LibP2PDB project image

    LibP2PDB

    • 198
    • Addons

    A lightweight, embeddable library for peer-to-peer distributed-database synchronization in WoW addons.

    • 198
    • April 14, 2026
    • Addons
    • +1
  • LibBloomFilter project image

    LibBloomFilter

    • 84
    • Addons

    Bloom Filter implementation for WoW Lua 5.1 environment

    • 84
    • February 26, 2026
    • Addons
    • +1
  • LibPatternedBloomFilter project image

    LibPatternedBloomFilter

    • 94
    • Addons

    Patterned Bloom Filter implementation for WoW Lua 5.1 environment

    • 94
    • February 16, 2026
    • Addons
    • +1