Reputation: 342
Which is the most easy way to lower the used memory space of a string and finally save it on the disc ?? (using java)
I heard about Hufmann Coding, but you need to create a tree in order to realize it. Another way should be bit shifting, because a character in ASCII always uses 1 byte of space...
That's the theory, but how to realize something like bit shifting in java, that really shrinks the strings memory usage on disc ??
Thanks in advance
Upvotes: 1
Views: 241
Reputation: 389
I might suggest some names on which you can read further using Google.
1) cannonic Hoffman coding - no need to store a tree But only the length of the symbols.
2) arithmetic encoding - A more interesting scenario is adaptive arithmetic coding that adapts the encoding to the probabilities of the words at encoding time.
3) front prefix coding - if words in your string have common prefixes like a dictionary for example, you might cut the prefix of a word and just store its length And on decoding get the prefix from the previous word Or a word in a certain index of the string that came before.
These are really easy to implement(also in java) and their pseudo code as well as elreal java implementations may be found in the first links of a Google search.
Of course there are many more techniques and the right ones depend on the actual use. If you expand your question and give a use case , others and I may be able to fine tune the technique to the scenario.
Upvotes: 1