Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluators (CanDecode & CompressionRatio) #2

Open
dbrown444 opened this issue Jun 23, 2018 · 2 comments
Open

Evaluators (CanDecode & CompressionRatio) #2

dbrown444 opened this issue Jun 23, 2018 · 2 comments

Comments

@dbrown444
Copy link

Hello there,

Cool project. I was wondering about the option of adding a bool for a byte[] bool = SmazSharp.CanDecode(input byte[]), and a compression ratio value. int ratio = SmazSharp.CompressionRatio(string input)

Thanks
Dave

@garysharp
Copy link
Owner

Hi Dave,
Thanks for your feedback.

Both of those suggestions would largely involve performing the actual compression/decompression. Presumably (depending on the output), you might then choose to perform the operation (or not?). It might be best to perform the compression/decompression and calculate the ratio yourself (as its meaning is a little complicated - see below).

While the source hasn't been optimised for allocations, it should be possible to have an allocation-free ratio calculator (if that's what you're worried about):

int SmazSharp.CalculateCompressedSize(string Input)
float SmazSharp.CalculateCompressedRatio(string Input)

and then:

int SmazSharp.CalculateDecompressedSize(byte[] Input)

This is slightly complicated, as the string type in .Net is in Unicode encoding, but Smaz only compresses ASCII. Should the ratio be compared to an ASCII encoded string, or it's Unicode? Is the size equal to the number of characters in the string, or the number of bytes it occupies?

Regarding, the SmazSharp.CanDecode suggestion, how do you feel about the try pattern? For example:

bool SmazSharp.TryDecompress(byte[] Input, out string Output)

Gary

@dbrown444
Copy link
Author

Thank you, thank you! Long circle back here, but did some initial experimentation and wow. This is so slick code. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants