-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e0c3e2
commit 04ceb72
Showing
11 changed files
with
59 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Aha | ||
# 用于存储单调递增的整数序列, 能够对序列进行压缩 | ||
struct EliasFano(T) | ||
@bytes : UInt8* | ||
@length : UInt64 | ||
@u : T | ||
|
||
def self.round_up(val : UInt64, den : UInt64) : UInt64 | ||
val = val == 0 ? den : val | ||
return (val % den == 0) ? val : val + (den - (val % den)) | ||
end | ||
|
||
# Returns the number of lower bits required to encode each element in an | ||
# array of size length with maximum value u | ||
def self.get_l(u : UInt32, length : UInt32) | ||
x = round_up(u.to_u64, length.to_u64) / length | ||
return (sizeof(T) << 3) - Aha.leading_zero(x - 1) | ||
end | ||
|
||
def initialize(ptr : T*, @length : UInt64) | ||
@u = ptr[length - 1] | ||
l = self.class.get_l u, length | ||
@bytes = Pointer(UInt8).malloc(compressed_size(@u, @length)) | ||
low_bits_offset = 0 | ||
high_bits_offset = round_up l * @length, 8 | ||
prev = 0 | ||
(0...@length).each do |i| | ||
# @TODO | ||
end | ||
end | ||
|
||
def [](idx : UInt64) : T | ||
end | ||
|
||
def self.compressed_size(u, length) | ||
l = get_l u, length | ||
num_low_bits = round_up l * length, 8 | ||
num_high_bits = round_up 2 * length, 8 | ||
(num_low_bits + num_high_bits) / 8 | ||
end | ||
end | ||
end |
Empty file.
Oops, something went wrong.