String compression
- Posted by "Hayden McKay" <hmck1 at dodo.com.au> Dec 16, 2003
- 504 views
--=======AVGMAIL-3FDF13F749BC======= ------=_NextPart_000_0009_01C3C43B.88D9DE40 I noticed that people were concerned about string memory usage so I came up with this. To my knowlege an integer is stored as an integer regardless of its length, (since computers store such things in binary). Please correct me if I'm wrong. Its not much but a good start, modify it as u see fit. include machine.e -- integer = p_ints(integer digit, integer digit) -- Pack two integers onto one integer. -- Returns a single integer. global function p_ints(integer a,integer b) sequence s atom n s = int_to_bits(a,16) s &= int_to_bits(b,16) n = bits_to_int(s) return n end function -- sequence = u_ints(integer digit) -- Unpack integer into two integers. -- Returns a double integer sequence. global function u_ints(integer n) sequence s object a s = int_to_bits(n,32) a = bits_to_int(s[1..16]) a &= bits_to_int(s[17..32]) return a end function I have another routine that compresses whole words into an integer, but since two different words can equal the same integer I run into problems reversing it. (it only works for certain words about 5 - 10% of the time). (95% of the time I get different run_time errors.) I have three theorys to over come this. 1. Store a digit on the end as a seed to reversing the word. eg: the length of the word. 2. Compress word to a decimal atom to contain a seed in itself. 3. It cannot be done! If any one knows were I can find related topics it be much helpfull. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.551 / Virus Database: 343 - Release Date: 11/12/03 ------=_NextPart_000_0009_01C3C43B.88D9DE40 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1276" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>I noticed that people were concerned about string memory usage so I came up with this.</FONT></DIV> <DIV><FONT face=Arial size=2>To my knowlege an integer is stored as an integer regardless</FONT></DIV> <DIV><FONT face=Arial size=2>of its length, (since computers store such things in binary).</FONT></DIV> <DIV><FONT face=Arial size=2>Please correct me if I'm wrong. </FONT></DIV> <DIV><FONT face=Arial size=2>Its not much but a good start, modify it as u see fit.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>include machine.e<BR>-- integer = p_ints(integer digit, integer digit)<BR>-- Pack two integers onto one integer.<BR>-- Returns a single integer.<BR>global function p_ints(integer a,integer b)<BR>sequence s<BR>atom n<BR> s = int_to_bits(a,16)<BR> s &= int_to_bits(b,16)<BR> n = bits_to_int(s)<BR> return n<BR>end function<BR>-- sequence = u_ints(integer digit)<BR>-- Unpack integer into two integers.<BR>-- Returns a double integer sequence.<BR>global function u_ints(integer n)<BR>sequence s<BR>object a<BR> s = int_to_bits(n,32)<BR> a = bits_to_int(s[1..16])<BR> a &= bits_to_int(s[17..32])<BR> return a<BR>end function</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>I have another routine that compresses whole words into an integer, but since two different words can equal the same integer I run into problems reversing it. (it only works for certain words about 5 - 10% of the time). </FONT></DIV> <DIV><FONT face=Arial size=2>(95% of the time I get different run_time errors.)</FONT></DIV> <DIV><FONT face=Arial size=2>I have three theorys to over come this.</FONT></DIV> <DIV><FONT face=Arial size=2>1. Store a digit on the end as a seed to reversing the word.</FONT></DIV> <DIV><FONT face=Arial size=2>eg: the length of the word.</FONT></DIV> <DIV><FONT face=Arial size=2>2. Compress word to a decimal atom to contain a seed in itself.</FONT></DIV> <DIV><FONT face=Arial size=2>3. It cannot be done!</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> If any one knows were I can find related topics it be much helpfull. </FONT></DIV> <DIV><FONT face=Arial size=2> </DIV> <DIV><BR></DIV></FONT> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2><BR>---<BR>Outgoing mail is certified Virus Free.<BR>Checked by AVG anti-virus system (<A href="http://www.grisoft.com">http://www.grisoft.com</A>).<BR>Version: 6.0.551 / ------=_NextPart_000_0009_01C3C43B.88D9DE40-- --=======AVGMAIL-3FDF13F749BC======= Content-Type: text/plain; x-avg=cert; charset=iso-8859-2 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Description: "AVG certification" Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.551 / Virus Database: 343 - Release Date: 12/12/03 --=======AVGMAIL-3FDF13F749BC=======--