redis数据结构-intset

整数集合是纯整数时set的底层实现

typedef struct intset {
    uint32_t encoding; 
    uint32_t length;
    int8_t contents[];
} intset;
  • encoding表示数组内的变量的类型,一共三个枚举值(int16,int32,int64)
  • length表示集合中元素个数
  • contents存放数据

整数集合的特点

  • 有序无重复
  • 元素的类型可以升级,但不能降级,这样可以使数组更灵活,更节约空间。
原文地址:https://www.cnblogs.com/liuboyuan/p/14731505.html