From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 8 Jun 2018 06:26:40 +0300 From: Konstantin Osipov Subject: Re: [tarantool-patches] Re: [PATCH v2 1/1] box: create bigrefs for tuples Message-ID: <20180608032640.GB6866@chai> References: <9c250cefbee4375f722235eaf234b734bf98b83d.1527867534.git.imeevma@gmail.com> <8844c62d-284e-3461-d5cb-969dedbe5348@tarantool.org> <871b6d2c-677c-00f4-230f-25782a6b4fd1@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <871b6d2c-677c-00f4-230f-25782a6b4fd1@tarantool.org> To: tarantool-patches@freelists.org Cc: Vladimir Davydov , Imeev Mergen List-ID: * Vladislav Shpilevoy [18/06/05 00:01]: > +static inline void > +bigref_list_delete_index(uint16_t index) > +{ > + bigref_list.refs[index] = 0; > + if (--bigref_list.size == 0) { > + bigref_list_destroy(); > + return; > + } > + if (bigref_list.capacity == BIGREF_MIN_CAPACITY || > + bigref_list.size > bigref_list.capacity / BIGREF_FACTOR) > + return; > + > + uint16_t top_index = bigref_list.capacity - 1; > + while (bigref_list.refs[top_index] == 0) > + top_index--; > + > + uint16_t needed_capacity = top_index + 1; > + if (needed_capacity < BIGREF_MIN_CAPACITY) > + needed_capacity = BIGREF_MIN_CAPACITY; > + if (needed_capacity > bigref_list.capacity / BIGREF_FACTOR) > + return; > + /* Round up capacity to the next highest power of 2. */ > + assert(sizeof(needed_capacity) == sizeof(uint16_t)); > + needed_capacity--; > + needed_capacity |= needed_capacity >> 1; > + needed_capacity |= needed_capacity >> 2; > + needed_capacity |= needed_capacity >> 4; > + needed_capacity |= needed_capacity >> 8; > + assert(needed_capacity < UINT16_MAX); > + needed_capacity++; This is perhaps a very elegant piece of code, but it has no test. And a functional test for it would be difficult. Could you please write a unit test? -- Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 http://tarantool.io - www.twitter.com/kostja_osipov