encyclopegia.org

Hi/Lo algorithm

Hi/Lo is an algorithm and a key generation strategy used for generating unique keys for use in a database as a primary key. It uses a sequence-based hi-lo pattern to generate values. Hi/Lo is used in scenarios where an application needs its entities to have an identity prior to persistence. It is a value generation strategy. An alternative to Hi/Lo would be for the application to generate keys as universally unique identifiers (UUID).

Hi/Lo is an algorithm and a key generation strategy used for generating unique keys for use in a database as a primary key. It uses a sequence-based hi-lo pattern to generate values. Hi/Lo is used in scenarios where an application needs its entities to have an identity prior to persistence. It is a value generation strategy. An alternative to Hi/Lo would be for the application to generate keys as universally unique identifiers (UUID). current_hi := get_next_hi() current_lo := 0 key := current_hi × max_lo + current_lo current_lo := current_lo + 1 return key class HiloKeyGenerator: """Key generator that uses a Hi/Lo algorithm. Args: get_next_hi: A callable function that retrieves a new high value. max_lo: The maximum low value. Defaults to 1000. Raises: ValueError: If the value of max_lo is not greater than zero. """ def __init__(self, get_next_hi: Callable[[], int], max_lo: int = 1000) -> None: if max_lo int: """Generate a new unique key.""" if self._current_lo >= self._max_lo: self._current_hi = self._get_next_hi() self._current_lo = 0 key = self._current_hi * self._max_lo + self._current_lo self._current_lo += 1 return key Output: >>> def get_next_hi(): ... return 2 # From database server. ... >>> generator = HiloKeyGenerator(get_next_hi) >>> generator.generate_key() 2000 >>> generator.generate_key() 2001 >>> generator.generate_key() 2002

References

No reference rows published for this article.

Cite this article

MLA

"Hi/Lo algorithm." encyclopegia.org, 2026, https://encyclopegia.org/wiki/hi-lo-algorithm. Accessed 24 November 2026.

Chicago

"Hi/Lo algorithm." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/hi-lo-algorithm.

APA

encyclopegia.org. (2026). Hi/Lo algorithm. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/hi-lo-algorithm

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Lo Espejo

stub · references available

Xarel·lo

stub · references available

μ-law algorithm

stub · references available

Te Lo Agradezco, Pero No

stub · references available

Park Seung-hi

stub · references available

Hi-Standard

stub · references available

bitap algorithm

stub · references available

QR algorithm

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1331627826 · 0.5 · snapshot enwiki-001331627826

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.