squeeze: An example of how it works


The example beneath is designed to explain how squeeze works, and not how (un-)effective it is as a compression tool.

Input

Input parameter: Input value(s): Description etc.:
mode 0 Always set this to '0' on first call, leave untouched thereafter
algorithm 4 Defines the compression algorithm no. to use,
4: try to compress defined values in 'idata()' in groups of 2 or 3
ldat 29 No. of elements in the 'idata()' array prior to compression, including 'leading' and 'trailing';
will be reset if compression is successful (see information on output variables below)
leading 1 No. of leading elements in 'idata()' that the users does not wish to compress
trailing 1 No. of trailing elements in 'idata()' that the users does not wish to compress
length 29 Total no. of elements in 'idata()'; left unchanged by squeeze
idata
Element # 12345 678910
Value 98828385822 28268128218
Element # 1112131415 1617181920
Value - 32767- 32767- 32767 - 32767- 32767 - 32767822888128
Element # 2122232425 26272829 
Value 118218188208218 198188178790 
array prior to compression (leading entries, field, trailing entries)
maxsize 27 Dimension of the work array 'iwork()';
in the 2D case, this must be set >= nx*ny, etc.
nfactors 263 Dimension of 'factors()';
should be set >= 263 for the present case ('algorithm'=4)
factors ... Factors used in the construction of a compressed set of values;
will be set on first call (when 'mode'=1), and reset on subsequent calls if the compression algorithm is changed (i.e., if the value of 'algorithm' is changed)

Action

  1. Disregard leading and trailing entries; in this case, only consider elements 2 through 28 (inclusive)

  2. Store first value to consider during compression (no. 'leading'+1=2 as "single value":
    28   ->   -32768   28 (-32768 marks the next integer*2 as "single value")
    RESULT:   -32768   28

  3. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries ('algorithm'=4 packs <= 3 entries as 1):
    |#3 - #2|:  d1 = |38 - 28| =10
    |#4 - #3|:  d2 = |58 - 38| =20
    |#5 - #4|:  d3 = |22 - 58| =36
    'algorithm' = 4 works as follows:
    Accordingly, we compress d1 and d2 as one value:
    10, 20   ->    - (10 + 181*20) - 1   
    RESULT:   - 3631

  4. We have now stored differences without specifying the signs of the differences. When decompressing    - 3631    we find that this represents   10, 20    but we have no knowledge of whether the the second entry to consider is   28 + 10   or    28 - 10. So next, we find the bitwise representation of the first 16 differences
    entriesdifference categoryvalue value
    (accumulative)
    #3 - #2:10>= 0 0 * (2**0)0
    #4 - #3:20>= 0 0 * (2**1)0
    #5 - #4:- 36< 0 1 * (2**2)4
    #6 - #5:6>= 0 0 * (2**3)4
    #7 - #6:-2< 0 1 * (2**4)20
    #8 - #7:- 18< 0 1 * (2**5)52
    #9 - #8:120>= 0 0 * (2**6)52
    #10 - #9:4000>= 0 0 * (2**7)52
    #11 - #10:- 36985< 0 1 * (2**8)308
    #12 - #11:0>= 0 0 * (2**9)308
    #13 - #12:0>= 0 0 * (2**10)308
    #14 - #13:0>= 0 0 * (2**11)308
    #15 - #14:0>= 0 0 * (2**12)308
    #16 - #15:0>= 0 0 * (2**13)308
    #17 - #16:32849>= 0 0 * (2**14)308
    #18 - #17:- 54< 0 1 * (2**15)33076
    Adjust the accumlative value to integer*2 range:
    33076   ->   33076 - 32768
    RESULT:   308

  5. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#5 - #4|:  d1 = |22 - 58| =36
    |#6 - #5|:  d2 = |28 - 22| =6
    |#7 - #6|:  d3 = |26 - 28| =2
    Accordingly, we compress d1 and d2 as one value:
    36, 6   ->    - (36 + 181*6) - 1   
    RESULT:   - 1123
    Note that the bitwise representation of the signs of differences have been stored.

  6. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#7 - #6|:  d1 = |26 - 28| =2
    |#8 - #7|:  d2 = |8 - 26| =18
    |#9 - #8|:  d3 = |128 - 8| =120
    Accordingly, we compress d1 and d2 as one value:
    2, 18   ->    - (2 + 181*18) - 1   
    RESULT:   - 3261
    Note that the bitwise representation of the signs of differences have been stored.

  7. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#9 - #8|:  d1 = |128 - 8| =120
    |#10 - #9|:  d2 = |218 - 128| =90
    |#11 - #10|:    Not considered, since #11 = 'undef'
    Accordingly, we compress d1 and d2 as one value:
    120, 90   ->    - (120 + 181*90) - 1   
    RESULT:   - 16411
    Note that the bitwise representation of the signs of differences have been stored.

  8. The next entry (#11) is the undefined value.
    Special algorithm: Accordingly, since there are 6 consequtive undefined values
    6   ->   32762
    RESULT:   - 32767   32762
    The bitwise signs of differences are irrelevant for consequtive undefined values.

  9. The first defined value after consequtive undefined values are stored as a single value:
    RESULT:   -32768   82
    Note that the bitwise representation of the signs of differences have been stored.

  10. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#18 - #17|:  d1 = |28 - 82| =54
    |#19 - #18|:  d2 = |88 - 28| =60
    |#20 - #19|:  d3 = |128 - 88| =40
    Accordingly, we compress d1 and d2 as one value:
    54, 60   ->    - (54 + 181*60) - 1   
    RESULT:   - 10915

  11. We have not stored the sign of the difference 'd2' above. So next, we find the bitwise representation of the final differences
    entriesdifference categoryvalue value
    (accumulative)
    #19 - #18:60>= 0 0 * (2**0)0
    #20 - #19:40>= 0 0 * (2**1)0
    #21 - #20:- 10< 0 1 * (2**2)4
    #22 - #21:100>= 0 0 * (2**3)4
    #23 - #22:-30< 0 1 * (2**4)20
    #24 - #23:20>= 0 0 * (2**5)20
    #25 - #24:10>= 0 0 * (2**6)20
    #26 - #25:- 20< 0 1 * (2**7)148
    #27 - #26:- 10< 0 1 * (2**8)404
    #28 - #27:- 10< 0 1 * (2**9)916
    Adjust the accumlative value to integer*2 range:
    916   ->   916 - 32768
    RESULT:   - 31852

  12. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#20 - #19|:  d1 = |128 - 88| =40
    |#21 - #20|:  d2 = |118 - 128| =10
    |#22 - #21|:  d3 = |118 - 218| =100
    Accordingly, we compress d1 and d2 as one value:
    40, 10   ->    - (40 + 181*10) - 1   
    RESULT:   - 1851

  13. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#22 - #21|:  d1 = |118 - 218| =100
    |#23 - #22|:  d2 = |188 - 218| =30
    |#24 - #23|:  d3 = |208 - 188| =20
    Accordingly, we compress d1 and d2 as one value:
    100, 30   ->    - (100 + 181*30) - 1   
    RESULT:   - 5531

  14. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#24 - #23|:  d1 = |208 - 188| =20
    |#25 - #24|:  d2 = |218 - 208| =10
    |#26 - #25|:  d3 = |198 - 218| =20
    Accordingly, we compress d1, d2 and d3 as one value:
    20, 30, 20   ->    20 + 32*10 + 32*32*20   =    20 + 32*10 + 1024*20
    RESULT:   20820

  15. Compress the next values as differences; first, find the absolute value of the differences of the next 3 entries:
    |#27 - #26|:  d1 = |188 - 198| =10
    |#28 - #27|:  d2 = |178 - 188| =10
    Accordingly, we compress d1 and d2 as one value:
    100, 30   ->    - (10 + 181*10) - 1   
    RESULT:   - 1821

  16. Is the compression successful? Here, the sum above becomes 17 + 1 + 1 + 5 = 24, and 'length' = 29, so by definition, the compression has been successful. Hence, "squeeze" returns 'mode' = 1 (if unsuccessful compression occurs, 'mode' = -1 will be returned).

Output

Output parameter: Output value(s): Description etc.:
mode 1 see explanation above (item 16)
ldat 24 reset to 'leading' + 5 + 'trailing' + no. of compressed values
idata
Element # 12*3* 4*5*6* 78
Value 988- 32767- 32767- 32768 - 327514- 3276828
Element # 9101112 13141516
Value - 3631308- 1123- 3261 - 16411- 3276732762- 32768
Element # 17181920 21222324
Value 82- 10915- 31852- 1851 - 553120820- 1821790
compressed array (leading entries, compressed field, trailing entries)
    1: leading entry
    2*: 'leading' - 32768
    3*: 'trailing' - 32768
    4*: int(# compressed entries/65536) - 32768
    5*: mod(# compressed entries, 65536) - 32768
    6*: compression algorithm no.
    7 - 23: compressed array
    24: trailing entry
factors
# Value
n = 1, 17 20, 21, ..., 216
n=18 4 ('algorithm')
n = 19, 82 0*32, 0*(322), 1*32, 1*(322), ..., 31*32, 31*(322)
n = 83, 263       0*181, 1*181, ..., 180*181
factors used in the construction of a compressed set of values, when 'algorithm' = 4

Famous last words