comparison mercurial/revlogutils/nodemap.py @ 44315:7762a295fd4d

nodemap: use an explicit "Block" object in the reference implementation This will help us to introduce some test around the data currently written on disk. Differential Revision: https://phab.mercurial-scm.org/D7842
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:48:28 +0100
parents 7f4f7ef3133e
children 55b12f2593c1
comparison
equal deleted inserted replaced
44314:7f4f7ef3133e 44315:7762a295fd4d
214 def _to_int(hex_digit): 214 def _to_int(hex_digit):
215 """turn an hexadecimal digit into a proper integer""" 215 """turn an hexadecimal digit into a proper integer"""
216 return int(hex_digit, 16) 216 return int(hex_digit, 16)
217 217
218 218
219 class Block(dict):
220 """represent a block of the Trie
221
222 contains up to 16 entry indexed from 0 to 15"""
223
224
219 def _build_trie(index): 225 def _build_trie(index):
220 """build a nodemap trie 226 """build a nodemap trie
221 227
222 The nodemap stores revision number for each unique prefix. 228 The nodemap stores revision number for each unique prefix.
223 229
224 Each block is a dictionary with keys in `[0, 15]`. Values are either 230 Each block is a dictionary with keys in `[0, 15]`. Values are either
225 another block or a revision number. 231 another block or a revision number.
226 """ 232 """
227 root = {} 233 root = Block()
228 for rev in range(len(index)): 234 for rev in range(len(index)):
229 hex = nodemod.hex(index[rev][7]) 235 hex = nodemod.hex(index[rev][7])
230 _insert_into_block(index, 0, root, rev, hex) 236 _insert_into_block(index, 0, root, rev, hex)
231 return root 237 return root
232 238
251 else: 257 else:
252 # collision with a previously unique prefix, inserting new 258 # collision with a previously unique prefix, inserting new
253 # vertices to fit both entry. 259 # vertices to fit both entry.
254 other_hex = nodemod.hex(index[entry][7]) 260 other_hex = nodemod.hex(index[entry][7])
255 other_rev = entry 261 other_rev = entry
256 new = {} 262 new = Block()
257 block[hex_digit] = new 263 block[hex_digit] = new
258 _insert_into_block(index, level + 1, new, other_rev, other_hex) 264 _insert_into_block(index, level + 1, new, other_rev, other_hex)
259 _insert_into_block(index, level + 1, new, current_rev, current_hex) 265 _insert_into_block(index, level + 1, new, current_rev, current_hex)
260 266
261 267