1. RE: needing help with database.e addition.

> -----Original Message-----
> From: Jonathan Leger [mailto:jleger at amerisafe.com]

> I would like to make '248' a "special" case, too,
> and compress the value 248 as a two-byte integer
> instead of a one byte in compress().  What do I
> need to change to get this to work?  All of my
> efforts have failed...



Not sure what you've already tried, but it looks like you'll need to change
MAX1B to 238 and add constants for U2B, MINU2B and MAXU2B.  Then in
(de)compress():

-- Compressed format of Euphoria objects on disk
--
-- First byte:
--          0..247    -- immediate small integer, -9 to 238
<------------------
		      -- since small negative integers -9..-1 might be
common
constant 
       U2B = 248,   -- 2-byte unsigned integer follows  <----------------
       I2B = 249,   -- 2-byte signed integer follows
	 I3B = 250,   -- 3-byte signed integer follows
	 I4B = 251,   -- 4-byte signed integer follows
	 F4B = 252,   -- 4-byte f.p. number follows
	 F8B = 253,   -- 8-byte f.p. number follows
	 S1B = 254,   -- sequence, 1-byte length follows, then elements
	 S4B = 255    -- sequence, 4-byte length follows, then elements

constant MIN1B = -9,
	 MAX1B = 239,
	 MINU2B = 0,
	 MAXU2B = power(2, 15),
	 MIN2B = -power(2, 15),
	 MAX2B =  power(2, 15)-1,
	 MIN3B = -power(2, 23),
	 MAX3B =  power(2, 23)-1,
	 MIN4B = -power(2, 31)

function decompress()
-- read a compressed Euphoria object from disk
    integer c
    sequence s
    atom len
    
    c = getc(current_db)
    
    if c >= 0 and c <= 247 then  -- Change to <= 247    <-------------------
	return c + MIN1B
    
    elsif c = U2B then
      return getc(current_db) + 
	       #100 * getc(current_db)

    elsif c = I2B then
	return getc(current_db) + 
	       #100 * getc(current_db) +
	       MIN2B

.....
Then in compress:

function compress(object x)
-- return the compressed representation of a Euphoria object 
-- as a sequence of bytes
    sequence x4, s
    
    if atom(x) then
	if integer(x) then
	    if x >= MIN1B and x <= MAX1B then
		return {x - MIN1B}

-- ADD THIS *******************************************
	    elsif x >= MINU2B and x <= MAXU2B then             
		return {U2B, and_bits(x, #FF), floor(x / #100)}
-- ****************************************************

	    elsif x >= MIN2B and x <= MAX2B then
		x -= MIN2B
		return {I2B, and_bits(x, #FF), floor(x / #100)}
	    
	    elsif x >= MIN3B and x <= MAX3B then
		x -= MIN3B
		return {I3B, and_bits(x, #FF), and_bits(floor(x / #100),
#FF), floor(x / #10000)}
	    
	    else
		return I4B & int_to_bytes(x-MIN4B) 


Matt Lewis

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu