Level / abstract-leveldown

An abstract prototype matching the leveldown API.
MIT License
146 stars 53 forks source link

Question: the proper way to pass some specific tests. #315

Closed plainweaver closed 5 years ago

plainweaver commented 5 years ago

Is there a recommended way to pass iterator tests passing option as below:

vweevers commented 5 years ago

It's hard to tell which tests you're referring to. Can you link to specific lines in iterator-range-test.js?

It might help to look at other implementations for inspiration, and to read the documentation of levelup, leveldown and LevelDB.

vweevers commented 5 years ago

And could you share some details about your implementation? It's OK if you can't, but it'll be more difficult to help you.

plainweaver commented 5 years ago

Thanks for a passionate response. I'm wondering since there are eccentric usages over normal javascript strings and numbers.

https://github.com/Level/abstract-leveldown/blob/af123487c01dc29419b95d1b06445b2ef81e8c04/test/iterator-range-test.js#L93-L95

https://github.com/Level/abstract-leveldown/blob/af123487c01dc29419b95d1b06445b2ef81e8c04/test/iterator-range-test.js#L290-L293

What do they mean? Am I missing something?

vweevers commented 5 years ago

In a nutshell, they test that the implementation sorts keys lexicographically. Numbers are a good way to do that, because they shouldn't sort "naturally".

plainweaver commented 5 years ago

Why would '40000' ~ '50000' contains '45' ?

Isn't it correct when it should only contains longer ones? It looks more natural when '40' ~ '50' containing '45555'

plainweaver commented 5 years ago

If then, looks able to be done with radix tree.

vweevers commented 5 years ago

Why would '40000' ~ '50000' contains '45' ?

Keys are compared character by character (or byte by byte), stopping at inquality. Comparing '45' and '40000', '4' is equal to '4' and '5' is greater than '0' so therefore '45' comes after '40000'.

If a consumer of an abstract-leveldown implementation wants to sort numbers naturally, they can either zero-pad their keys so that '45' becomes e.g. '00045', or to save space, use an encoding like lexicographic-integer.

If then, looks able to be done with radix tree.

Can't say if that's the right choice, without knowing anything about your implementation and its underlying storage.