-
-
Save tilgovi/1057573 to your computer and use it in GitHub Desktop.
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
chunkify(InList, BaseChunkSize) -> | |
%%io:format("length of list is ~p and chunk size is ~p ~n",[length(InList),BaseChunkSize]), | |
case byte_size(term_to_binary(InList)) of | |
Size when Size > BaseChunkSize -> | |
NumberOfChunksLikely = ((Size div BaseChunkSize) + 1), | |
ChunkThreshold = Size div NumberOfChunksLikely, | |
chunkify(InList, ChunkThreshold, [], 0, []); | |
_Else -> | |
[InList] | |
end. | |
chunkify([], _ChunkThreshold, [], 0, OutputChunks) -> | |
lists:reverse(OutputChunks); | |
chunkify([], _ChunkThreshold, OutList, _OutListSize, OutputChunks) -> | |
lists:reverse([lists:reverse(OutList) | OutputChunks]); | |
chunkify([InElement | RestInList], ChunkThreshold, OutList, OutListSize, OutputChunks) -> | |
case byte_size(term_to_binary(InElement)) of | |
Size when (Size + OutListSize) > ChunkThreshold andalso OutList /= [] | |
andalso length(OutList) > 9 -> | |
{Left, Right} = lists:split(length(OutList)/2, OutList), | |
chunkify(RestInList, ChunkThreshold, [], 0, [lists:reverse([InElement | Right]) | lists:reverse(Left, OutputChunks)]); | |
Size -> | |
chunkify(RestInList, ChunkThreshold, [InElement | OutList], OutListSize + Size, OutputChunks) | |
end. |
Author
tilgovi
commented
Jul 1, 2011
via email
I know. It's confusing. But it's also maybe next to useless with an
append-only strategy. We have to rewrite the node(s) anyway on each write
whether chunkify makes one or multiple chunks.
On the other hand, it _might_ have a positive effect on disk usage since the
nodes might tend to remain smaller for longer.
On Jul 1, 2011 4:02 AM, "bdionne" < [email protected]> wrote:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment