当前位置:网站首页>Redis (4) -- Talking about integer set
Redis (4) -- Talking about integer set
2022-06-26 07:22:00 【cb414】
1, Preface
Set of integers (intset) Is one of the underlying implementations of set keys , When a set contains only integer value elements , And when the number of elements in this collection is small ,Redis We will use the integer set as the underlying implementation of the set key
Redis Other data structures related to are as follows :
Simple dynamic string
Linked list
Dictionaries
2, Set of integers
If a set key , When all the stored elements are integer values , Then the underlying implementation of this integer key will be an integer set
SADD numbers 1 3 5 7 9
# See what data structure is used at the bottom of the collection key
OBJECT ENCODING numbers
2.1, structure
The related structure of this integer set is as follows :
typedef struct intset{
// Encoding mode
uint32_t encoding;
// Number of elements contained in the collection
uint32_t length;
// Array to hold elements
int8_t contents[];
} intset;
2.1.1,contents
contents An array is the underlying implementation of an integer set : Every element of the set of integers is contents Each element item of the array , Each element item is arranged in the array according to the size of the value from small to large , And there are no duplicates in the array
2.1.2,length
This property records contents Number of elements in the array
2.1.3,encoding
Although mentioned above contents It's a int8_t Array of , But actually contents What type of value to save depends on encoding Value encoding There are several options :
int8_t: use 8 A digit number represents an integer value ( The minimum is -32768, The maximum is 32767)int32_t: use 32 A digit number represents an integer value ( The minimum is -2 147 483 648, The maximum is 2 147 483 647)int64_t: use 64 A digit number represents an integer value ( The minimum is -9 223 372 036 854 775 808, The maximum is 9 223 372 036 854 775 807)
2.1.4, Example

encodingThe value bit ofINSET_ENC_INT16Represents the underlying implementation of an integer set as int16_t An array of types , What is kept isint16_tInteger value of typelengthThe attribute is 5, Indicates that the integer set stores five elementscontentsArrays store elements in descending order- Because every set element is
int16_tInteger value of type , thereforecontentsThe size of the array is equal to 80 position
2.2, upgrade
Suppose you have a set of integers A, Inside contents yes int16_t An array of types , So when we gather A There is more than... Stored in int16_t Integer of value range ( Suppose that this integer can be used as int32_t Storage ) when , Will trigger the upgrade , Upgrade the integer set
The upgrade steps are as follows :
- According to the type of new elements , Expand the space size of the array at the bottom of the integer set , And allocate space for new elements
- Convert all elements of the underlying array to be of the same type as the new element , And put it in the right place , And in this process, it is necessary to ensure the storage from small to large
- Add new elements to the underlying array
- And then
encodingTo change the value ofINSET_ENC_INT32, And willlengthFrom 3 Change it to 4
The benefits of upgrading
The upgrade strategy of integer sets has two advantages :
- Improve the flexibility of integer set
- Integer collections can be adapted to new elements by upgrading the underlying array , So that users do not have to worry about type errors
- To save memory
- Upgrading allows a collection to hold three different types of values at the same time ( In this case, the array type will be
INSET_ENC_INT64), It can also ensure that the upgrade will only be carried out when necessary
- Upgrading allows a collection to hold three different types of values at the same time ( In this case, the array type will be
Downgrade
The integer set does not support demotion , Once the array is upgraded , The code will always be upgraded
边栏推荐
- 职场“大冤种”,不仅身累,心也被掏空……
- Tetradecanoxy tetraphenylporphyrin methacrylate mm-tpp-14c; Cetanoxy tetraphenyl porphyrin methacrylate mm-tpp-16c; Purple solid; Qiyue supply
- Cache usage
- 13. Mismatch simulation of power synthesis for ads usage recording
- GMP模型
- Jemter 壓力測試 -基礎請求-【教學篇】
- 3,3 '- di (3,4-dicarboxyphenoxy) -4,4' - diphenylethynylbiphenyldianhydride (bpebpda) / porphyrin 2dcofs (H2P COF, ZNP COF and cup COF) supplied by Qiyue
- Porphyrin based polyimide ppbpis (ppbpi-pa, ppbpi-pepa and ppbpi-pena); Crosslinked porphyrin based polyimide (ppbpi-pa-cr, ppbpi-pepa-cr, ppbpi-pena-cr) reagent
- Sanic based services use celery to complete dynamic modification timing tasks
- 一文搞懂Glide,不懂来打我
猜你喜欢

Paths with a certain value in a binary tree (1) (2) (3) (Sword finger offer)

Redis系列——redis启动,客户端day1-2
![5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes](/img/51/136eda75986fc01282558e626b2faf.jpg)
5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes
![Jemter stress test - visualization tool support - [installation]](/img/e9/9acda4e37c98cc21df9499684205c6.png)
Jemter stress test - visualization tool support - [installation]

少年,你可知 Kotlin 协程最初的样子?

Sanic based services use celery to complete dynamic modification timing tasks

Ppbpi-h-cr, ppbpimn Cr, ppbpi Fe Cr alkynyl crosslinked porphyrin based polyimide material Qiyue porphyrin reagent

Pytorch builds CNN LSTM hybrid model to realize multivariable and multi step time series forecasting (load forecasting)

GMP模型

How to publish function computing (FC) through cloud effect
随机推荐
多传感器融合感知
Dark red crystal meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin (co TAPP); Meso-5,10,15,20-tetra (p-aminophenyl) cobalt porphyrin no complex (TAPP co no) supplied by Qiyue
Pytorch builds CNN LSTM hybrid model to realize multivariable and multi step time series forecasting (load forecasting)
十大证券公司哪个佣金手续费最低,最安全可靠?
[recommend an entity class conversion tool mapstruct, which is powerful and easy to use]
GMP模型
Jemter 压力测试 -可视化工具支持-【安装篇】
item2安装配置及环境失效问题解决
【推荐10个 让你轻松的 IDEA 插件,少些繁琐又重复的代码】
报错问题Parameter index out of range(0 < 1) (1 > number of parameters,which is 0
Item2 installation configuration and environment failure solution
Error reported by using two-dimensional array [[]] in thymeleaf: could not parse as expression
JS modularization
Numpy learning challenge level 5 - create array
[image segmentation] blood vessel extraction from retinal fundus images based on maximum principal curvature with matlab code
5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes
Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display
Qt基础教程:QString
Multisensor fusion sensing
The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty