Design and implementation of Redis - Achieving data structure (c) with integers a jump table

Jump table  

First, the jump table is an ordered data structure to find their average complexity of O (logN), the worst time complexity is O (N), in most cases comparable with balanced tree. Redis implemented using it as an ordered set of nodes in the cluster, and as a data structure.

Skip data structure definition table below, for the Node left, to the right of the table:

Wherein the left hand is used to reverse the reverse traverse the list of the members must be robj storey unique, each node is a random number 1-32.

 

 

Integers

       When small integer set as the underlying implementation, the data structure defined as follows:

Each integer elements are arranged in order of size in the array, and no duplicates. Note that the type of contents of elements depends on the coding, rather than int8_t

upgrade

       What is the upgrade? When adding an element to the set of integers, if the type of the new element is longer than the original contents of the element type, it is necessary to upgrade first. Therefore, the time complexity of additive elements is O (N), and does not support an array of degraded ~

  1. Expand capacity on the basis of the original contents according to the type of the new element
  2. The old elements moving past (backwards movement)
  3. The new elements are added

This automatic upgrades so what good is it?

       First is certainly convenient, when adding elements regardless of the size range, it is not enough on their own growth; secondly, to save memory, only when you need it to use large integers int64 ~   

Published 47 original articles · won praise 8 · views 30000 +

Guess you like

Origin blog.csdn.net/nanchengyu/article/details/89316562