Redis integer data structures set -intset

When a set of elements contains only integer values, and the small number of elements of the collection, Redisuse the set of integers (intset)to store the set of elements.

intsetIt is a compact array of structures, while supporting 16bit, 32bit and 64bit integer.

structure

IntSet struct <T> { 
    Int32 encoding; // encoding 
    int32 length; // set the number of elements contained 
    int <T> contents []; // save element integer array 
} intset;

  

  • contentsAn array is set to achieve the underlying integer, each item sorted in ascending order in the array size value, and does not contain duplicate entries

upgrade

When adding a new element into the set of integers, if a new type of element than the set of integers conventional types of all elements to be long, integers need to upgrade the size of the underlying array extension, and then add

Upgrade strategy mainly in the following two benefits:

  • Enhance the flexibility of the set of integers

  • Conserve memory as much as possible

Note: the set of integers does not support downgrading operation, once the upgrade, code will remain after the upgrade status

Guess you like

Origin www.cnblogs.com/jeemzz/p/11443473.html