Jumpers: Why does Redis have to use jumpers to implement ordered collections rather than red-black trees?
  • The ordered collection of Redis is implemented by means of a hoptable, or, strictly speaking, a hash table. The core operations supported by Redis ordered collections are as follows:

    • Insert data
    • Delete a data
    • Find a piece of data
    • Find data by interval
    • Iterate over an ordered sequence
    • Among them, the operation of insert, delete, search and iteration output ordered sequence can also be completed by red-black tree, and the time complexity is O(logn). However, the red-black tree is not as efficient as the hop table in finding data by interval.
    • For the operation of finding data by interval, the skip table can locate the beginning of the interval in order (logn) time complexity, and then iterate through the original list.
  • Of course, there are other reasons why Redis uses hoppers for ordered collections. For example, the code for hoppers is much easier to implement, much easier to understand and write than red-black trees, and simplicity means better readability and less error prone. Skip tables are more flexible and can balance execution efficiency and memory consumption by changing index building strategies.

  • However, skip tables are no substitute for red-black trees. Because red-black trees predate hops, Map types in many programming languages are implemented through red-black trees.

  • Skip table is a dynamic data structure, support fast read insert, delete, search operations, time complexity is O(logn)