{"id":201191,"date":"2025-05-10T08:06:09","date_gmt":"2025-05-10T00:06:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201191\/"},"modified":"2025-05-10T08:06:09","modified_gmt":"2025-05-10T00:06:09","slug":"redis-%e6%95%b4%e6%95%b0%e9%9b%86%e5%90%88%e7%9a%84%e5%85%b7%e4%bd%93%e4%bd%bf%e7%94%a8intset","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201191\/","title":{"rendered":"Redis\u00a0\u6574\u6570\u96c6\u5408\u7684\u5177\u4f53\u4f7f\u7528(intset)"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Redis&nbsp;\u6574\u6570\u96c6\u5408\u7684\u5177\u4f53\u4f7f\u7528(intset)<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230golang\u5b66\u4e60\u7f51\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6570\u636e\u5e93\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aRedis&nbsp;\u6574\u6570\u96c6\u5408\u7684\u5177\u4f53\u4f7f\u7528(intset)\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0bRedis\u6574\u6570\u96c6\u5408\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<h2>\u4e00\u3001\u96c6\u5408\u6982\u8ff0<\/h2>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u5bf9\u4e8e\u96c6\u5408\uff0cSTL \u7684 set \u76f8\u4fe1\u5927\u5bb6\u90fd\u4e0d\u964c\u751f\uff0c\u5b83\u7684\u5e95\u5c42\u5b9e\u73b0\u662f\u7ea2\u9ed1\u6811\u3002\u65e0\u8bba\u63d2\u5165\u3001\u5220\u9664\u3001\u67e5\u627e\u90fd\u662f O(log n) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u5f53\u7136\uff0c\u5982\u679c\u7528\u54c8\u5e0c\u8868\u6765\u5b9e\u73b0\u96c6\u5408\uff0c\u63d2\u5165\u3001\u5220\u9664\u3001\u67e5\u627e\u90fd\u53ef\u4ee5\u8fbe\u5230 O(1)\u3002\u90a3\u4e48\u4e3a\u4ec0\u4e48\u96c6\u5408\u8981\u7528\u7ea2\u9ed1\u6811\u548c\u6ca1\u6709\u7528\u54c8\u5e0c\u8868\u5462\uff1f\u6211\u60f3\uff0c\u6700\u5927\u7684\u53ef\u80fd\u662f\u57fa\u4e8e\u96c6\u5408\u81ea\u8eab\u7684\u7279\u6027\uff0c\u96c6\u5408\u6709\u5b83\u7279\u6709\u7684\u64cd\u4f5c\uff1a\u6c42\u4ea4\u3001\u6c42\u5e76\u3001\u6c42\u5dee\u3002\u8fd9\u4e09\u4e2a\u64cd\u4f5c\u5bf9\u4e8e\u54c8\u5e0c\u8868\u6765\u8bf4\u90fd\u662f O(n) \u7684\u3002\u57fa\u4e8e\u8fd9\u4e00\u70b9\uff0c\u76f8\u6bd4\u65e0\u5e8f\u7684\u54c8\u5e0c\u8868\u6765\u8bf4\uff0c\u91c7\u7528\u6709\u5e8f\u7684\u7ea2\u9ed1\u6811\u4f1a\u66f4\u52a0\u5408\u9002\u3002<\/p>\n<h2>\u4e8c\u3001Redis \u6574\u6570\u96c6\u5408\uff08intset\uff09<\/h2>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u4eca\u5929\u8981\u8bb2\u7684\u6574\u6570\u96c6\u5408\uff0c\u53c8\u79f0\u4e3a intset\uff0c\u662f Redis \u7279\u6709\u7684\u6570\u636e\u7ed3\u6784\u3002\u5b83\u7684\u5b9e\u73b0\u65e2\u4e0d\u662f\u7ea2\u9ed1\u6811\uff0c\u4e5f\u4e0d\u662f\u54c8\u5e0c\u8868\u3002\u5c31\u662f\u7b80\u5355\u7684\u6570\u7ec4\u52a0\u4e0a\u5185\u5b58\u7f16\u7801\u3002\u5f53\u5b58\u50a8\u5143\u7d20\u8f83\u5c11\uff08 \u5143\u7d20\u4e2a\u6570\u4e0a\u9650\u5b9a\u4e49\u5728server.h \u7684 OBJ_SET_MAX_INTSET_ENTRIES \u5b8f\u5b9a\u4e49\u503c\u4e3a512\uff09\u4e14\u5747\u4e3a\u6574\u578b\u65f6\uff0c\u624d\u4f1a\u4f7f\u7528\u5230\u6574\u6570\u96c6\u5408\u3002\u5b83\u7684\u67e5\u627e\u662f O(log n) \u7684\uff0c\u63d2\u5165\u548c\u5220\u9664\u90fd\u662f O(n) \u7684\u3002\u4f46\u662f\u7531\u4e8e\u5b58\u50a8\u5143\u7d20\u76f8\u5bf9\u8f83\u5c11\u7684\u65f6\u5019\uff0cO(log n) \u548c&nbsp;O(n) \u5dee\u8ddd\u4e0d\u662f\u5f88\u5927\uff0c\u4f46\u662f\u7528 Redis \u7684\u8fd9\u79cd\u6574\u6570\u96c6\u5408\uff0c\u76f8\u6bd4\u7ea2\u9ed1\u6811\u548c\u54c8\u5e0c\u8868\u6765\u8bf4\uff0c\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u5185\u5b58\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \u6240\u4ee5\uff0cRedis \u7684 \u6574\u6570\u96c6\u5408 intset \u7684\u5b58\u5728\u4e3b\u8981\u8fd8\u662f\u4e3a\u4e86\u8282\u7701\u5185\u5b58\u3002<\/p>\n<h3>1\u3001intset \u7ed3\u6784\u5b9a\u4e49<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; intset \u7ed3\u6784\u5b9a\u4e49\u5728 intset.h \u4e2d\uff1a<\/p>\n<pre>#define INTSET_ENC_INT16 (sizeof(int16_t))\n#define INTSET_ENC_INT32 (sizeof(int32_t))\n#define INTSET_ENC_INT64 (sizeof(int64_t))\n \ntypedef struct intset {\n    uint32_t encoding;      \/* a *\/\n    uint32_t length;        \/* b *\/\n    int8_t contents[];      \/* c *\/\n} intset;<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; a) encoding \u6307\u5b9a\u4e86\u7f16\u7801\u65b9\u5f0f\uff0c\u603b\u5171\u6709 INTSET_ENC_INT16\u3001INTSET_ENC_INT32\u3001INTSET_ENC_INT64 \u4e09\u79cd\u3002\u4ece\u5b8f\u5b9a\u4e49\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u4e09\u4e2a\u503c\u5206\u522b\u4e3a 2\u30014\u30018\u3002\u4ece\u5b57\u9762\u610f\u601d\u53ef\u4ee5\u770b\u51fa\u4e09\u8005\u80fd\u8868\u793a\u7684\u8303\u56f4\u662f 16\u4f4d\u6574\u6570\u300132\u4f4d\u6574\u6570 \u4ee5\u53ca 64\u4f4d\u6574\u6570\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp; b) length \u5b58\u50a8\u4e86\u6574\u6570\u96c6\u5408\u7684\u5143\u7d20\u4e2a\u6570\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp; c) contents \u4e3a\u6574\u6570\u96c6\u5408\u7684\u67d4\u6027\u6570\u7ec4\uff0c\u5143\u7d20\u7c7b\u578b\u5e76\u4e0d\u4e00\u5b9a\u662f int8_t \u7c7b\u578b\u7684\u3002 contents \u4e0d\u5360\u7528\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\uff0c\u5b83\u53ea\u4f5c\u4e3a\u6574\u6570\u96c6\u5408\u6570\u636e\u7684\u9996\u6307\u9488\u3002\u6574\u6570\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u6309\u7167\u4ece\u5c0f\u5230\u5927\u7684\u987a\u5e8f\u5728 contents \u4e2d\u6392\u5217\u8d77\u6765\u3002<\/p>\n<h3>2\u3001\u7f16\u7801\u65b9\u5f0f<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u9996\u5148\uff0c\u6211\u4eec\u6765\u7406\u89e3\u7f16\u7801\u65b9\u5f0f encoding \u7684\u542b\u4e49\u3002\u9700\u8981\u660e\u786e\u7684\u4e00\u70b9\u662f\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u6574\u6570\u96c6\u5408\u6765\u8bf4\uff0c\u6240\u6709\u7684\u5143\u7d20\u7684\u7f16\u7801\u4e00\u5b9a\u662f\u4e00\u81f4\u7684\uff08\u5426\u5219\u6bcf\u4e2a\u6570\u90fd\u5f97\u5b58\u4e00\u4e2a\u7f16\u7801\uff0c\u800c\u4e0d\u662f\u5c06\u5b83\u5b58\u5728 intset \u7ed3\u6784\u4f53\u5185\u4e86\uff09\uff0c\u90a3\u4e48\u6574\u4e2a\u6574\u6570\u96c6\u5408\u7684\u7f16\u7801\u53d6\u51b3\u4e8e\u96c6\u5408\u4e2d\u201c\u7edd\u5bf9\u503c\u201d\u6700\u5927\u7684\u90a3\u4e2a\u6570\uff08\u4e4b\u6240\u4ee5\u662f\u7edd\u5bf9\u503c\uff0c\u56e0\u4e3a\u6574\u6570\u5305\u542b\u6b63\u6570\u548c\u8d1f\u6570\uff09\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\u901a\u8fc7\u90a3\u4e2a\u7edd\u5bf9\u503c\u6700\u5927\u7684\u6574\u6570\u6765\u83b7\u53d6\u7f16\u7801\uff0c\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>static uint8_t _intsetValueEncoding(int64_t v) {\n    if (v  INT32_MAX)\n        return INTSET_ENC_INT64;\n    else if (v  INT16_MAX)\n        return INTSET_ENC_INT32;\n    else\n        return INTSET_ENC_INT16;\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u8fd9\u6bb5\u4ee3\u7801\u7684\u542b\u4e49\u662f\uff0c\u5982\u679c\u6574\u6570 v \u4e0d\u80fd\u7528 32\u4f4d\u6574\u6570\u8868\u793a\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u7528&nbsp;INTSET_ENC_INT64 \u7f16\u7801\uff1b\u5982\u679c\u4e0d\u80fd\u7528 16\u4f4d\u6574\u6570\u8868\u793a\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u7528&nbsp;INTSET_ENC_INT32 \u7f16\u7801\uff1b\u5426\u5219\uff0c\u91c7\u7528&nbsp;INTSET_ENC_INT16 \u7f16\u7801\u5c31\u884c\u3002\u6838\u5fc3\u5c31\u662f\uff1a\u80fd\u75282\u4e2a\u5b57\u8282\u8868\u793a\u5c31\u4e0d\u75284\u4e2a\u5b57\u8282\uff0c\u80fd\u75284\u4e2a\u5b57\u8282\u8868\u793a\u5c31\u4e0d\u75288\u4e2a\u5b57\u8282\uff0c\u80fd\u7701\u5219\u7701\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \u51e0\u4e2a\u5b8f\u5b9a\u4e49\u5728 stdint.h \u4e2d\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>\/* Minimum of signed integral types. *\/ \n# define INT16_MIN      (-32767-1)  \n# define INT32_MIN      (-2147483647-1)  \n \n\/* Maximum of signed integral types. *\/  \n# define INT16_MAX      (32767)  \n# define INT32_MAX      (2147483647)  <\/pre>\n<h3>3\u3001\u7f16\u7801\u5347\u7ea7<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u5f53\u524d\u7f16\u7801\u65b9\u5f0f\u4e0d\u8db3\u4ee5\u5b58\u50a8\u66f4\u5927\u4f4d\u6570\u7684\u6574\u6570\u65f6\uff0c\u9700\u8981\u5347\u7ea7\u7f16\u7801\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4e0b\u56fe\u6240\u793a\u7684\u56db\u4e2a\u6570\u5b57\u90fd\u5728 [ -32768, 32767 ] \u8303\u56f4\u5185\uff0c\u6240\u4ee5\u91c7\u7528 INTSET_ENC_INT16 \u7f16\u7801\u5373\u53ef\u3002contents \u7684\u6570\u7ec4\u957f\u5ea6\u4e3a sizeof(int16_t) * 4 = 2 * 4 = 8 \u4e2a\u5b57\u8282 \uff08 \u537364\u4e2a\u4e8c\u8fdb\u5236\u4f4d \uff09\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167245561463afa5bea583c.png\" class=\"aligncenter\"><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u7136\u540e\u6211\u4eec\u63d2\u5165\u4e00\u4e2a\u6570\uff0c\u5b83\u7684\u503c\u4e3a 32768\uff0c\u6bd4 INT16_MAX \u59271\uff0c\u6240\u4ee5\u5b83\u9700\u8981\u91c7\u7528 INTSET_ENC_INT32 \u7f16\u7801\uff0c\u800c\u6574\u6570\u96c6\u5408\u4e2d\u6240\u6709\u7684\u6570\u7684\u7f16\u7801\u9700\u8981\u4fdd\u6301\u4e00\u81f4\u3002\u90a3\u4e48\uff0c\u6240\u6709\u6570\u7684\u7f16\u7801\u90fd\u9700\u8981\u8f6c\u4e3a&nbsp;INTSET_ENC_INT32 \u7f16\u7801\u3002\u8fd9\u5c31\u662f \u201c\u5347\u7ea7\u201d\u3002\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167245561463afa5bed236f.png\" class=\"aligncenter\"><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u5347\u7ea7\u5b8c\u540e\uff0ccontents \u6570\u7ec4\u7684\u957f\u5ea6\u53d8\u4e3a sizeof(int32_t) * 5&nbsp;= 4&nbsp;* 5&nbsp;= 20&nbsp;\u4e2a\u5b57\u8282 \uff08 \u5373160\u4e2a\u4e8c\u8fdb\u5236\u4f4d \uff09\u3002\u800c\u4e14\u6bcf\u4e2a\u5143\u7d20\u5360\u7528\u7684\u5185\u5b58\u90fd\u6269\u5927\u4e00\u500d\uff0c\u6240\u5728\u7684\u76f8\u5bf9\u4f4d\u7f6e\u4e5f\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u5bfc\u81f4\u6240\u6709\u7684\u5143\u7d20\u90fd\u9700\u8981\u5f80\u9ad8\u4f4d\u5185\u5b58\u8fc1\u79fb\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \u90a3\u6211\u4eec\u4e00\u5f00\u59cb\u5c31\u628a\u6240\u6709\u7684\u6574\u6570\u96c6\u5408\u90fd\u7528 INTSET_ENC_INT64 \u6765\u7f16\u7801\u4e0d\u5c31\u597d\u4e86\uff0c\u8fd8\u7701\u5f97\u9ebb\u70e6\u3002\u539f\u56e0\u662f Redis \u8bbe\u8ba1 intset \u7684\u521d\u8877\u8fd8\u662f\u4e3a\u4e86\u8282\u7701\u5185\u5b58\uff0c\u8bbe\u60f3\u4e00\u4e2a\u96c6\u5408\u7684\u5143\u7d20\u6c38\u8fdc\u90fd\u4e0d\u4f1a\u8d85\u8fc7 16\u4f4d \u6574\u6570\uff0c\u90a3\u4e48\u7528 64\u4f4d\u6574\u6570\u7684\u8bdd\uff0c\u76f8\u5f53\u4e8e\u6d6a\u8d39\u4e86 3\u500d \u7684\u5185\u5b58\u3002<\/p>\n<h2>\u4e09\u3001\u6574\u6570\u96c6\u5408\u5e38\u7528\u64cd\u4f5c<\/h2>\n<h3>1\u3001\u521b\u5efa\u96c6\u5408<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u521b\u5efa\u4e00\u4e2a\u6574\u6570\u96c6\u5408&nbsp;intsetNew\uff0c\u5b9e\u73b0\u5728 intset.c \u4e2d\uff1a<\/p>\n<pre>intset *intsetNew(void) {\n    intset *is = zmalloc(sizeof(intset));\n    is-&gt;encoding = intrev32ifbe(INTSET_ENC_INT16);\n    is-&gt;length = 0;\n    return is;\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u521d\u59cb\u521b\u5efa\u7684\u6574\u6570\u96c6\u5408\u4e3a\u7a7a\u96c6\u5408\uff0c\u7528 zmalloc \u8fdb\u884c\u5185\u5b58\u5206\u914d\u540e\uff0c\u5b9a\u4e49\u7f16\u7801\u4e3a INTSET_ENC_INT16\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u5185\u5b58\u5c3d\u91cf\u5c0f\u3002\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cintset \u7684\u5b58\u50a8\u76f4\u63a5\u6d89\u53ca\u5230\u5185\u5b58\u7f16\u7801\uff0c\u6240\u4ee5\u9700\u8981\u8003\u8651\u4e3b\u673a\u7684\u5b57\u8282\u5e8f\u95ee\u9898\uff08\u76f8\u5173\u8d44\u6599\u8bf7\u53c2\u9605\uff1a\u5b57\u8282\u5e8f\uff09\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;intrev32ifbe \u7684\u610f\u601d\u662f int32 reversal if big endian\u3002\u5373 \u5982\u679c\u5f53\u524d\u4e3b\u673a\u5b57\u8282\u5e8f\u4e3a\u5927\u7aef\u5e8f\uff0c\u90a3\u4e48\u5c06\u5b83\u7684\u5185\u5b58\u5b58\u50a8\u8fdb\u884c\u7ffb\u8f6c\u64cd\u4f5c\u3002\u7b80\u8a00\u4e4b\uff0cintset \u7684\u6240\u6709\u6210\u5458\u5b58\u50a8\u65b9\u5f0f\u90fd\u91c7\u7528\u5c0f\u7aef\u5e8f\u3002\u6240\u4ee5\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u6574\u6570\u96c6\u5408\uff0c\u5185\u5b58\u5206\u5e03\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167245561563afa5bf0bc71.png\" class=\"aligncenter\"><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u4e86\u89e3\u4e86\u6574\u6570\u96c6\u5408\u7684\u5185\u5b58\u7f16\u7801\u4ee5\u540e\uff0c\u6211\u4eec\u6765\u770b\u770b\u5b83\u7684 \u8bbe\u7f6e \uff08set\uff09\u548c \u83b7\u53d6\uff08get\uff09\u3002<\/p>\n<h3>2\u3001\u5143\u7d20\u8bbe\u7f6e<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u8bbe\u7f6e \u7684\u542b\u4e49\u5c31\u662f\u7ed9\u5b9a\u6574\u6570\u96c6\u5408\u4ee5\u53ca\u4e00\u4e2a\u4f4d\u7f6e\u548c\u503c\uff0c\u5c06\u503c\u8bbe\u7f6e\u5230\u8fd9\u4e2a\u6574\u6570\u96c6\u5408\u7684\u5bf9\u5e94\u4f4d\u7f6e\u4e0a\u3002_intsetSet \u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>static void _intsetSet(intset *is, int pos, int64_t value) {\n    uint32_t encoding = intrev32ifbe(is-&gt;encoding);          \/* a *\/\n \n    if (encoding == INTSET_ENC_INT64) {\n        ((int64_t*)is-&gt;contents)[pos] = value;               \/* b *\/\n        memrev64ifbe(((int64_t*)is-&gt;contents)+pos);          \/* c *\/\n    } else if (encoding == INTSET_ENC_INT32) {\n        ((int32_t*)is-&gt;contents)[pos] = value;\n        memrev32ifbe(((int32_t*)is-&gt;contents)+pos);\n    } else {\n        ((int16_t*)is-&gt;contents)[pos] = value;\n        memrev16ifbe(((int16_t*)is-&gt;contents)+pos);\n    }\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;a) \u5927\u7aef\u5e8f\u548c\u5c0f\u7aef\u5e8f\u53ea\u662f\u5b58\u50a8\u65b9\u5f0f\uff0cencoding \u5728\u5b58\u50a8\u7684\u65f6\u5019\u8fdb\u884c\u4e86\u4e00\u6b21 intrev32ifbe \u8f6c\u6362\uff0c\u53d6\u51fa\u6765\u7528\u7684\u65f6\u5019\u9700\u8981\u518d\u8fdb\u884c\u4e00\u6b21 intrev32ifbe \u8f6c\u6362\uff08\u5176\u5b9e\u5c31\u662f\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\uff09\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;b) \u6839\u636e encoding \u7684\u7c7b\u578b\uff0c\u5c06 contents \u8f6c\u6362\u6210\u6307\u5b9a\u7c7b\u578b\u7684\u6307\u9488\uff0c\u7136\u540e\u7528 pos \u8fdb\u884c\u7d22\u5f15\u627e\u5230\u5bf9\u5e94\u7684\u5185\u5b58\u4f4d\u7f6e\uff0c\u7136\u540e\u5c06 value \u7684\u503c\u8bbe\u7f6e\u5230\u5bf9\u5e94\u7684\u5185\u5b58\u4e2d\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;c) memrev64ifbe \u7684\u5b9e\u73b0\u53c2\u89c1&nbsp;\u5b57\u8282\u5e8f \u7684 memrev64 \u51fd\u6570\uff0c\u5373\u5c06\u5bf9\u5e94\u5185\u5b58\u7684\u503c\u8f6c\u6362\u6210\u5c0f\u7aef\u5e8f\u5b58\u50a8\u3002<\/p>\n<h3>3\u3001\u5143\u7d20\u83b7\u53d6<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u83b7\u53d6 \u7684\u542b\u4e49\u5c31\u662f\u7ed9\u5b9a\u6574\u6570\u96c6\u5408\u4ee5\u53ca\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u8fd4\u56de\u7ed9\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20\u7684\u503c\u3002_intsetGet \u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>static int64_t _intsetGetEncoded(intset *is, int pos, uint8_t enc) {\n    int64_t v64;\n    int32_t v32;\n    int16_t v16;\n \n    if (enc == INTSET_ENC_INT64) {\n        memcpy(&amp;v64,((int64_t*)is-&gt;contents)+pos,sizeof(v64));   \/* a *\/\n        memrev64ifbe(&amp;v64);                                      \/* b *\/\n        return v64;\n    } else if (enc == INTSET_ENC_INT32) {\n        memcpy(&amp;v32,((int32_t*)is-&gt;contents)+pos,sizeof(v32));\n        memrev32ifbe(&amp;v32);\n        return v32;\n    } else {\n        memcpy(&amp;v16,((int16_t*)is-&gt;contents)+pos,sizeof(v16));\n        memrev16ifbe(&amp;v16);\n        return v16;\n    }\n}\n \nstatic int64_t _intsetGet(intset *is, int pos) {\n    return _intsetGetEncoded(is,pos,intrev32ifbe(is-&gt;encoding));\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;a) \u6839\u636e encoding \u7684\u7c7b\u578b\uff0c\u5c06 contents \u8f6c\u6362\u6210\u6307\u5b9a\u7c7b\u578b\u7684\u6307\u9488\uff0c\u7136\u540e\u7528 pos \u8fdb\u884c\u7d22\u5f15\u627e\u5230\u5bf9\u5e94\u7684\u5185\u5b58\u4f4d\u7f6e\uff0c\u5c06\u5185\u5b58\u4f4d\u7f6e\u4e0a\u7684\u503c\u62f7\u8d1d\u5230\u4e34\u65f6\u53d8\u91cf\u4e2d\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;b) \u7531\u4e8e\u662f\u76f4\u63a5\u7684\u5185\u5b58\u62f7\u8d1d\uff0c\u6240\u4ee5\u53d6\u51fa\u6765\u7684\u503c\u8fd8\u662f\u5c0f\u7aef\u5e8f\u7684\uff0c\u90a3\u4e48\u5728\u5927\u7aef\u5e8f\u7684\u4e3b\u673a\u4e0a\u5f97\u5230\u7684\u503c\u662f\u4e0d\u5bf9\u7684\uff0c\u6240\u4ee5\u9700\u8981\u518d\u505a\u4e00\u6b21&nbsp;memrev64ifbe \u8f6c\u6362\u5c06\u503c\u8fd8\u539f\u3002<\/p>\n<h3><strong>&nbsp;4\u3001\u5143\u7d20\u67e5\u627e<\/strong><\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u7531\u4e8e\u6574\u6570\u96c6\u5408\u662f\u6709\u5e8f\u96c6\u5408\uff0c\u6240\u4ee5\u67e5\u627e\u67d0\u4e2a\u5143\u7d20\u662f\u5426\u5728\u6574\u6570\u96c6\u5408\u4e2d\uff0cRedis \u91c7\u7528\u7684\u662f\u4e8c\u5206\u67e5\u627e\u3002intsetSearch \u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>static uint8_t intsetSearch(intset *is, int64_t value, uint32_t *pos) {\n    int min = 0, max = intrev32ifbe(is-&gt;length)-1, mid = -1;\n    int64_t cur = -1;\n    if (intrev32ifbe(is-&gt;length) == 0) {\n        if (pos) *pos = 0;                                        \/* a *\/\n        return 0;\n    } else {                                                      \/* b *\/\n        if (value &gt; _intsetGet(is,intrev32ifbe(is-&gt;length)-1)) {\n            if (pos) *pos = intrev32ifbe(is-&gt;length);\n            return 0;\n        } else if (value = min) {                                          \n        mid = ((unsigned int)min + (unsigned int)max) &gt;&gt; 1;       \/* c *\/\n        cur = _intsetGet(is,mid);\n        if (value &gt; cur) {\n            min = mid+1;\n        } else if (value \n<p>&nbsp; &nbsp; &nbsp; &nbsp;a) \u6574\u6570\u96c6\u5408\u4e3a\u7a7a\uff0c\u8fd4\u56de0\u8868\u793a\u67e5\u627e\u5931\u8d25\uff1b<br>&nbsp; &nbsp; &nbsp; &nbsp;b) value \u7684\u503c\u6bd4\u6574\u6570\u96c6\u5408\u4e2d\u7684\u6700\u5927\u503c\u8fd8\u5927\uff0c\u6216\u8005\u6bd4\u6700\u5c0f\u503c\u8fd8\u5c0f\uff0c\u5219\u8fd4\u56de0\u8868\u793a\u67e5\u627e\u5931\u8d25\uff1b<br>&nbsp; &nbsp; &nbsp; &nbsp;c) \u6267\u884c\u4e8c\u5206\u67e5\u627e\uff0c\u5c06\u627e\u5230\u7684\u503c\u5b58\u5728 cur \u4e2d\uff1b<br>&nbsp; &nbsp; &nbsp; &nbsp;d) \u5982\u679c\u627e\u5230\u5219\u8fd4\u56de1\uff0c\u8868\u793a\u67e5\u627e\u6210\u529f\uff0c\u5e76\u4e14\u5c06 pos \u8bbe\u7f6e\u4e3a mid \u5e76\u8fd4\u56de\uff1b\u5982\u679c\u6ca1\u627e\u5230\u5219\u8fd4\u56de\u4e00\u4e2a\u9700\u8981\u63d2\u5165\u7684\u4f4d\u7f6e\u3002<\/p>\n<h3>5\u3001\u5185\u5b58\u91cd\u5206\u914d<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u7531\u4e8e contents \u7684\u5185\u5b58\u662f\u52a8\u6001\u5206\u914d\u7684\uff0c\u6240\u4ee5\u6bcf\u6b21\u8fdb\u884c\u5143\u7d20\u63d2\u5165\u6216\u8005\u5220\u9664\u7684\u65f6\u5019\uff0c\u90fd\u9700\u8981\u91cd\u65b0\u5206\u914d\u5185\u5b58\uff0c\u8fd9\u4e2a\u5b9e\u73b0\u653e\u5728 intsetResize \u4e2d\uff0c\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>static intset *intsetResize(intset *is, uint32_t len) {\n    uint32_t size = len*intrev32ifbe(is-&gt;encoding);\n    is = zrealloc(is,sizeof(intset)+size);\n    return is;\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;encoding \u672c\u8eab\u8868\u793a\u5b57\u8282\u4e2a\u6570\uff0c\u6240\u4ee5\u4e58\u4e0a\u96c6\u5408\u4e2a\u6570 len \u5c31\u662f contents \u6570\u7ec4\u9700\u8981\u7684\u603b\u5b57\u8282\u6570\u4e86\uff0c\u8c03\u7528 zrealloc \u8fdb\u884c\u5185\u5b58\u91cd\u5206\u914d\uff0c\u7136\u540e\u8fd4\u56de\u91cd\u65b0\u5206\u914d\u540e\u7684\u5730\u5740\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;\u6ce8\u610f\uff1azrealloc \u7684\u8fd4\u56de\u503c\u5fc5\u987b\u8fd4\u56de\u51fa\u53bb\uff0c\u56e0\u4e3a intset \u5728\u8fdb\u884c\u5185\u5b58\u91cd\u5206\u914d\u4ee5\u540e\uff0c\u5730\u5740\u53ef\u80fd\u5c31\u53d8\u4e86\u3002\u5373 is = zrealloc(is, ...) \u4e2d\uff0c\u6b64 is \u975e\u5f7c is\u3002\u6240\u4ee5\uff0c\u6240\u6709\u8c03\u7528 intsetResize \u7684\u51fd\u6570\u90fd\u9700\u8981\u8fde\u5e26\u7684\u8fd4\u56de\u65b0\u7684 intset \u6307\u9488\u3002<\/p>\n<h3>6\u3001\u7f16\u7801\u5347\u7ea7<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u7f16\u7801\u5347\u7ea7\u4e00\u5b9a\u53d1\u751f\u5728\u5143\u7d20\u63d2\u5165\uff0c\u5e76\u4e14\u63d2\u5165\u7684\u5143\u7d20\u7684\u7edd\u5bf9\u503c\u6bd4\u6574\u6570\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u90fd\u5927\u7684\u65f6\u5019\uff0c\u6240\u4ee5\u6211\u4eec\u628a\u5347\u7ea7\u540e\u7684\u5143\u7d20\u63d2\u5165\u548c\u7f16\u7801\u5347\u7ea7\u653e\u5728\u4e00\u4e2a\u51fd\u6570\u5b9e\u73b0\uff0c\u540d\u66f0&nbsp;intsetUpgradeAndAdd\uff0c\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>static intset *intsetUpgradeAndAdd(intset *is, int64_t value) {\n    uint8_t curenc = intrev32ifbe(is-&gt;encoding);\n    uint8_t newenc = _intsetValueEncoding(value);                             \n    int length = intrev32ifbe(is-&gt;length);\n    int prepend = value encoding = intrev32ifbe(newenc);\n    is = intsetResize(is,intrev32ifbe(is-&gt;length)+1);                        \/* b *\/\n    while(length--)\n        _intsetSet(is,length+prepend,_intsetGetEncoded(is,length,curenc));   \/* c *\/\n    if (prepend)\n        _intsetSet(is,0,value);\n    else\n        _intsetSet(is,intrev32ifbe(is-&gt;length),value);                       \/* d *\/\n    is-&gt;length = intrev32ifbe(intrev32ifbe(is-&gt;length)+1);\n    return is;\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;a) curenc \u8bb0\u5f55\u5347\u7ea7\u524d\u7684\u7f16\u7801\uff0cnewenc \u8bb0\u5f55\u5347\u7ea7\u540e\u7684\u7f16\u7801\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;b) \u5c06\u6574\u6570\u96c6\u5408 is \u7684\u7f16\u7801\u8bbe\u7f6e\u6210\u65b0\u7684\u7f16\u7801\u540e\uff0c\u8fdb\u884c\u5185\u5b58\u91cd\u5206\u914d\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;c) \u83b7\u53d6\u539f\u5148\u5185\u5b58\u4e2d\u7684\u6570\u636e\uff0c\u8bbe\u7f6e\u5230\u65b0\u5185\u5b58\u4e2d\uff08\u6ce8\u610f\uff1a\u7531\u4e8e\u4e24\u6bb5\u5185\u5b58\u7a7a\u95f4\u662f\u91cd\u53e0\u7684\uff0c\u800c\u4e14\u65b0\u5185\u5b58\u7684\u957f\u5ea6\u4e00\u5b9a\u5927\u4e8e\u539f\u5148\u5185\u5b58\uff0c\u6240\u4ee5\u9700\u8981\u4ece\u540e\u5f80\u524d\u8fdb\u884c\u62f7\u8d1d\uff09\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;d) \u5f53\u63d2\u5165\u7684\u503c value \u4e3a\u8d1f\u6570\u7684\u65f6\u5019\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u96c6\u5408\u7684\u6709\u5e8f\u6027\uff0c\u9700\u8981\u63d2\u5165\u5230 contents \u7684\u5934\u90e8\uff1b\u53cd\u4e4b\uff0c\u63d2\u5165\u5230\u5c3e\u90e8\uff1b\u5f53 value \u4e3a\u8d1f\u6570\u65f6 prepend \u4e3a1\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u5728\u5185\u5b58\u62f7\u8d1d\u7684\u65f6\u5019\u5c06\u7b2c 0 \u4e2a\u4f4d\u7f6e\u7559\u7a7a\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;\u5982\u56fe\u5c55\u793a\u4e86\u4e00\u4e2a (-32768, 0, 1, 32767) \u7684\u6574\u6570\u96c6\u5408\u5728\u63d2\u5165\u6570\u5b57 32768 \u540e\u7684\u5347\u7ea7\u7684\u5b8c\u6574\u8fc7\u7a0b\uff1a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" style=\"max-width:100%\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167245561563afa5bf6b605.png\" class=\"aligncenter\"><\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u6574\u6570\u96c6\u5408\u5347\u7ea7\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f O(n) \u7684\uff0c\u4f46\u662f\u5728\u6574\u6570\u96c6\u5408\u7684\u751f\u547d\u671f\u5185\uff0c\u5347\u7ea7\u6700\u591a\u53d1\u751f\u4e24\u6b21\uff08\u4ece INTSET_ENC_INT16 \u5230 INTSET_ENC_INT32 \u4ee5\u53ca \u4ece INTSET_ENC_INT32 \u5230 INTSET_ENC_INT64\uff09\u3002<\/p>\n<h3><strong>7\u3001\u5185\u5b58\u8fc1\u79fb<\/strong><\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \u7edd\u5927\u591a\u6570\u60c5\u51b5\u90fd\u662f\u5728\u6267\u884c \u63d2\u5165 \u3001\u5220\u9664 \u3001\u67e5\u627e \u64cd\u4f5c\u3002\u63d2\u5165 \u548c \u5220\u9664 \u4f1a\u6d89\u53ca\u5230\u8fde\u7eed\u5185\u5b58\u7684\u79fb\u52a8\u3002Redis \u7684\u5185\u90e8\u5b9e\u73b0\u4e2d\u6709\u4e00\u4e2a\u51fd\u6570 intsetMoveTail \u5c31\u662f\u7528\u6765\u5b9e\u73b0\u5185\u5b58\u79fb\u52a8\u7684\u3002<\/p>\n<pre>static void intsetMoveTail(intset *is, uint32_t from, uint32_t to) {\n    void *src, *dst;\n    uint32_t bytes = intrev32ifbe(is-&gt;length)-from;   \/* a *\/\n    uint32_t encoding = intrev32ifbe(is-&gt;encoding);\n \n    if (encoding == INTSET_ENC_INT64) {\n        src = (int64_t*)is-&gt;contents+from;                   \n        dst = (int64_t*)is-&gt;contents+to;              \n        bytes *= sizeof(int64_t);                     \/* b *\/\n    } else if (encoding == INTSET_ENC_INT32) {\n        src = (int32_t*)is-&gt;contents+from;\n        dst = (int32_t*)is-&gt;contents+to;\n        bytes *= sizeof(int32_t);\n    } else {\n        src = (int16_t*)is-&gt;contents+from;\n        dst = (int16_t*)is-&gt;contents+to;\n        bytes *= sizeof(int16_t);\n    }\n    memmove(dst,src,bytes);                           \/* c *\/\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;a) \u7edf\u8ba1\u4ece from \u5230\u7ed3\u5c3e\uff0c\u6709\u591a\u5c11\u4e2a\u5143\u7d20\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;b) \u6839\u636e\u4e0d\u540c\u7684\u7f16\u7801\uff0c\u8ba1\u7b97\u51fa\u9700\u8981\u62f7\u8d1d\u7684\u5185\u5b58\u5b57\u8282\u6570 bytes\uff0c\u4ee5\u53ca\u62f7\u8d1d\u6e90\u4f4d\u7f6e src\uff0c\u62f7\u8d1d\u76ee\u6807\u4f4d\u7f6e dst\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;c) memmove \u662f string.h \u4e2d\u7684\u51fd\u6570\uff1asrc\u6307\u5411\u7684\u5185\u5b58\u533a\u57df\u62f7\u8d1d bytes \u4e2a\u5b57\u8282\u5230 dst \u6240\u6307\u5411\u7684\u5185\u5b58\u533a\u57df\uff0c\u8fd9\u4e2a\u51fd\u6570\u662f\u652f\u6301\u5185\u5b58\u91cd\u53e0\u7684\uff1b<\/p>\n<h3>8\u3001\u5143\u7d20\u63d2\u5165<\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u6700\u540e\uff0c\u8bb2\u6574\u6570\u96c6\u5408\u7684\u63d2\u5165\u548c\u5220\u9664\uff0c\u63d2\u5165\u8c03\u7528\u7684\u662f&nbsp;intsetAdd\uff0c\u5728 intset.c \u4e2d\u5b9e\u73b0\uff1a<\/p>\n<pre>intset *intsetAdd(intset *is, int64_t value, uint8_t *success) {\n    uint8_t valenc = _intsetValueEncoding(value);\n    uint32_t pos;\n    if (success) *success = 1;\n    if (valenc &gt; intrev32ifbe(is-&gt;encoding)) {                               \/* a *\/\n        return intsetUpgradeAndAdd(is,value);\n    } else {\n        if (intsetSearch(is,value,&amp;pos)) {                                \n            if (success) *success = 0;                                       \/* b *\/\n            return is;\n        }\n        is = intsetResize(is,intrev32ifbe(is-&gt;length)+1);                    \/* c *\/\n        if (pos length)) intsetMoveTail(is,pos,pos+1);    \/* d *\/\n    }\n    _intsetSet(is,pos,value);                                                 \n    is-&gt;length = intrev32ifbe(intrev32ifbe(is-&gt;length)+1);                   \/* e *\/\n    return is;\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;a)&nbsp;\u63d2\u5165\u7684\u6570\u503c value \u7684\u5185\u5b58\u7f16\u7801\u5927\u4e8e\u73b0\u6709\u96c6\u5408\u7684\u7f16\u7801\uff0c\u76f4\u63a5\u8c03\u7528&nbsp;intsetUpgradeAndAdd \u8fdb\u884c\u7f16\u7801\u5347\u7ea7\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;b) \u96c6\u5408\u5143\u7d20\u662f\u4e0d\u91cd\u590d\u7684\uff0c\u5982\u679c intsetSearch \u80fd\u591f\u627e\u5230\uff0c\u5219\u5c06 success \u7f6e\u4e3a0\uff0c\u8868\u793a\u6b64\u6b21\u63d2\u5165\u5931\u8d25\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;c) \u5982\u679c intsetSearch \u627e\u4e0d\u5230\uff0c\u5c06 intset \u8fdb\u884c\u5185\u5b58\u91cd\u5206\u914d\uff0c\u5373 \u957f\u5ea6 \u52a0 1\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;d) pos \u4e3a&nbsp;intsetSearch \u8fc7\u7a0b\u4e2d\u627e\u5230\u7684 value \u5c06\u8981\u63d2\u5165\u7684\u4f4d\u7f6e\uff0c\u6211\u4eec\u5c06 pos \u4ee5\u540e\u7684\u5185\u5b58\u5411\u540e\u79fb\u52a81\u4e2a\u5355\u4f4d \uff08\u8fd9\u91cc\u76841\u4e2a\u5355\u4f4d\u53ef\u80fd\u662f2\u4e2a\u5b57\u8282\u30014\u4e2a\u5b57\u8282\u6216\u80058\u4e2a\u5b57\u8282\uff0c\u53d6\u51b3\u4e8e\u5f53\u524d\u6574\u6570\u96c6\u5408\u7684\u5185\u5b58\u7f16\u7801\uff09\u3002<br \/>&nbsp; &nbsp; &nbsp; &nbsp;e) \u8c03\u7528 _intsetSet \u5c06 value \u7684\u503c\u8bbe\u7f6e\u5230 pos \u7684\u4f4d\u7f6e\u4e0a\uff0c\u7136\u540e\u7ed9\u6210\u5458\u53d8\u91cf length \u52a0&nbsp;1\u3002\u6700\u540e\u8fd4\u56de intset \u6307\u9488\u9996\u5730\u5740\uff0c\u56e0\u4e3a\u5176\u95f4\u8fdb\u884c\u4e86 intsetResize\uff0c\u4f20\u5165\u7684 intset \u6307\u9488\u548c\u8fd4\u56de\u7684\u6709\u53ef\u80fd\u4e0d\u662f\u540c\u4e00\u4e2a\u4e86\u3002<\/p>\n<h3><strong>&nbsp;9\u3001\u5143\u7d20\u5220\u9664<\/strong><\/h3>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;\u5220\u9664\u5143\u7d20\u8c03\u7528\u7684\u662f&nbsp;intsetRemove \uff0c\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>intset *intsetRemove(intset *is, int64_t value, int *success) {\n    uint8_t valenc = _intsetValueEncoding(value);\n    uint32_t pos;\n    if (success) *success = 0;\n    if (valenc encoding) &amp;&amp; intsetSearch(is,value,&amp;pos)) {  \/* a *\/\n        uint32_t len = intrev32ifbe(is-&gt;length);\n        if (success) *success = 1;\n        if (pos length = intrev32ifbe(len-1); \n    }\n    return is;\n}<\/pre>\n<p>&nbsp; &nbsp; &nbsp; &nbsp;a) \u5f53\u6574\u6570\u96c6\u5408\u4e2d\u5b58\u5728 value \u8fd9\u4e2a\u5143\u7d20\u65f6\u624d\u80fd\u6267\u884c\u5220\u9664\u64cd\u4f5c\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;b) \u5982\u679c\u80fd\u901a\u8fc7 intsetSearch \u627e\u5230\u5143\u7d20\uff0c\u90a3\u4e48\u5b83\u7684\u4f4d\u7f6e\u5c31\u5728 pos \u4e0a\uff0c\u8fd9\u662f\u901a\u8fc7 intsetMoveTail \u5c06\u5185\u5b58\u5f80\u524d\u632a\uff1b<br \/>&nbsp; &nbsp; &nbsp; &nbsp;c) intsetResize \u91cd\u65b0\u5206\u914d\u5185\u5b58\uff0c\u5e76\u4e14\u5c06\u96c6\u5408\u957f\u5ea6\u51cf1\uff1b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis&nbsp;\u6574\u6570\u96c6\u5408\u7684&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201191","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201191"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201191\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}