真正简单的短字符串压缩 [英] Really simple short string compression

查看:580
本文介绍了真正简单的短字符串压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于长度约255个字符的字符串,有一个非常简单的压缩技术(是的,我压缩网址)?

Is there a really simple compression technique for strings up to about 255 characters in length (yes, I'm compressing URLs)?

我不关心压缩的强度 - 我正在寻找一个执行得很好,快速实现的东西。我想要比 SharpZipLib 更简单的东西:可以用几个简短的方法实现的东西。

I am not concerned with the strength of compression - I am looking for something that performs very well and is quick to implement. I would like something simpler than SharpZipLib: something that can be implemented with a couple of short methods.

推荐答案

我认为这里的关键问题是为什么要压缩网址?

I think the key question here is "Why do you want to compress URLs?"

尝试缩短地址栏的长网址?

更好地将原始URL存储在某个地方(数据库,文本文件...)和非域部分的哈希码(MD5很好)。然后,您可以有一个简单的页面(或一些HTTPModule,如果你感觉闪光)读取MD5和查找真实的URL。这是TinyURL和其他人的工作方式。

You're better storing the original URL somewhere (database, text file ...) alongside a hashcode of the non-domain part (MD5 is fine). You can then have a simple page (or some HTTPModule if you're feeling flashy) to read the MD5 and lookup the real URL. This is how TinyURL and others work.

例如:

http://mydomain.com/folder1/folder2/page1.aspx

可能会被短接至: / p>

Could be shorted to:

http://mydomain.com/2d4f1c8a

使用压缩库无法使用。字符串将被压缩成一个较短的二进制表示,但是将它转换回一个需要作为URL的一部分有效的字符串(例如Base64)将会抵消从压缩中获得的任何好处。

Using a compression library for this will not work. The string will be compressed into a shorter binary representation, but converting this back to a string which needs to be valid as part of a URL (e.g. Base64) will negate any benefit you gained from the compression.

在内存或磁盘上存储大量网址?

使用System.IO中的内置压缩库。压缩或ZLib库,这是简单和令人难以置信的好。因为你将存储二进制数据,压缩的输出将是原样。您需要将其解压缩以将其用作网址。

Use the built in compressing library within System.IO.Compression or the ZLib library which is simple and incredibly good. Since you will be storing binary data the compressed output will be fine as-is. You'll need to uncompress it to use it as a URL.

这篇关于真正简单的短字符串压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆