From ca15ff6a2c3c0c970bd888dd25c28222ff61a47d Mon Sep 17 00:00:00 2001 From: Mahone-h <731978588@qq.com> Date: Mon, 8 Nov 2021 13:23:28 +0800 Subject: [PATCH] =?UTF-8?q?skiplist=20insert=20grow=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E9=9A=8F=E6=9C=BA=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原版 insert grow 之后max_level改变,生成的随机level仍按旧max_level生成,导致后续索引中之后0 1level有节点 --- c-cpp/17_skiplist/skiplist_tr.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/c-cpp/17_skiplist/skiplist_tr.hpp b/c-cpp/17_skiplist/skiplist_tr.hpp index 8e931d7f..4a2a6d43 100644 --- a/c-cpp/17_skiplist/skiplist_tr.hpp +++ b/c-cpp/17_skiplist/skiplist_tr.hpp @@ -43,6 +43,11 @@ class random_level { public: random_level(IntType max_level, double prob) : dist(max_level - 1, prob) {} inline IntType operator()() const { return dist(gen); } + void reInit(IntType max_level,double prob){ + typename std::binomial_distribution::param_type newParm(max_level - 1, prob); + dist.param(newParm); + dist.reset(); + } }; } // namespace skiplist_detail @@ -246,7 +251,8 @@ class skiplist { iterator head = cont_.begin(); auto beg_head = head->forwards.end(); head->forwards.resize(max_lv_, tail); - + + rl_.reInit(max_lv_, prob_); return; } else { #ifdef LIAM_UT_DEBUG_