kkdai/maglev ? reverse-engineered prompt
Reverse engineered prompt
Build me a Go package that implements Google’s Maglev hashing for consistent backend selection.
I want to give it a list of backend names and a prime sized lookup table, then be able to look up any key and always get the same backend unless the backend list changes. It should support creating a table, getting a backend for a key, adding and removing backends, replacing the whole list, listing the current backends, and clearing everything. Make it safe to use from multiple goroutines, return clear errors when the table size is not prime, when there are too many backends, when a backend already exists or is missing, and when there are no backends.
Please keep the mapping deterministic and independent of the order backends were added. Use a fast hash based approach so lookups are just one hash and one table read. Add tests for minimal disruption when a backend is removed, and make sure the public API feels simple and easy to use. If you need to check current Go docs or hashing details, look them up online.