diff options
author | Christopher Haster <chaster@utexas.edu> | 2017-10-17 03:08:47 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2017-10-18 08:44:30 +0300 |
commit | 46e22b2a383528b0733971f8f84550bc6754b939 (patch) | |
tree | 94a0ac58cd714ec9cffca89339205b9a629494ad /lfs_util.h | |
parent | 4fdca15a0d938ac93e734f444a18ed1d3770a3ff (diff) |
Adopted lfs_ctz_index implementation using popcount
This reduces the O(n^2logn) runtime to read a file to only O(nlog).
The extra O(n) did not touch the disk, so it isn't a problem until the
files become very large, but this solution comes with very little cost.
Long story short, you can find the block index + offset pair for a
CTZ linked-list with this series of formulas:
n' = floor(N / (B - 2w/8))
N' = (B - 2w/8)n' + (w/8)popcount(n')
off' = N - N'
n, off =
n'-1, off'+B if off' < 0
n', off'+(w/8)(ctz(n')+1) if off' >= 0
For the long story, you will need to see the updated DESIGN.md
Diffstat (limited to 'lfs_util.h')
-rw-r--r-- | lfs_util.h | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -41,6 +41,10 @@ static inline uint32_t lfs_npw2(uint32_t a) { return 32 - __builtin_clz(a-1); } +static inline uint32_t lfs_popc(uint32_t a) { + return __builtin_popcount(a); +} + static inline int lfs_scmp(uint32_t a, uint32_t b) { return (int)(unsigned)(a - b); } |