minor cleanup of compression.inflate
							parent
							
								
									b350345f69
								
							
						
					
					
						commit
						a182b1835b
					
				|  | @ -1,13 +1,12 @@ | ||||||
| ! Copyright (C) 2009 Marc Fauconneau. | ! Copyright (C) 2009 Marc Fauconneau. | ||||||
| ! See http://factorcode.org/license.txt for BSD license. | ! See http://factorcode.org/license.txt for BSD license. | ||||||
| USING: accessors arrays assocs byte-vectors combinators | USING: accessors arrays assocs byte-vectors combinators | ||||||
| compression.huffman fry hashtables io.binary kernel locals math | combinators.smart compression.huffman fry hashtables io.binary | ||||||
| math.bitwise math.order math.ranges sequences sorting ; | kernel literals locals math math.bitwise math.order math.ranges | ||||||
|  | sequences sorting ; | ||||||
| QUALIFIED-WITH: bitstreams bs | QUALIFIED-WITH: bitstreams bs | ||||||
| IN: compression.inflate | IN: compression.inflate | ||||||
| 
 | 
 | ||||||
| QUALIFIED-WITH: bitstreams bs |  | ||||||
| 
 |  | ||||||
| <PRIVATE | <PRIVATE | ||||||
| 
 | 
 | ||||||
| : enum>seq ( assoc -- seq ) | : enum>seq ( assoc -- seq ) | ||||||
|  | @ -29,13 +28,6 @@ ERROR: bad-zlib-header ; | ||||||
|     2 data bs:seek                      ! compression level; ignore |     2 data bs:seek                      ! compression level; ignore | ||||||
|     ; |     ; | ||||||
| 
 | 
 | ||||||
| :: default-table ( -- table ) |  | ||||||
|     0 <hashtable> :> table |  | ||||||
|     0 143 [a,b] 280 287 [a,b] append 8 table set-at |  | ||||||
|     144 255 [a,b] >array 9 table set-at |  | ||||||
|     256 279 [a,b] >array 7 table set-at  |  | ||||||
|     table enum>seq 1 tail ; |  | ||||||
| 
 |  | ||||||
| CONSTANT: clen-shuffle { 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15 } | CONSTANT: clen-shuffle { 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15 } | ||||||
| 
 | 
 | ||||||
| : get-table ( values size -- table )  | : get-table ( values size -- table )  | ||||||
|  | @ -67,13 +59,17 @@ CONSTANT: clen-shuffle { 16 17 18 0 8 7 9 6 10 5 11 4 12 3 13 2 14 1 15 } | ||||||
|     [ dup array? [ second 0 <repetition> ] [ 1array ] if ] map concat |     [ dup array? [ second 0 <repetition> ] [ 1array ] if ] map concat | ||||||
|     nip swap cut 2array [ [ length>> [0,b) ] [ ] bi get-table ] map ; |     nip swap cut 2array [ [ length>> [0,b) ] [ ] bi get-table ] map ; | ||||||
| 
 | 
 | ||||||
| : static-huffman-tables ( -- tables ) | CONSTANT: static-huffman-tables  | ||||||
|  |     $[ | ||||||
|  |         [ | ||||||
|             0 143 [a,b] [ 8 ] replicate |             0 143 [a,b] [ 8 ] replicate | ||||||
|             144 255 [a,b] [ 9 ] replicate append |             144 255 [a,b] [ 9 ] replicate append | ||||||
|             256 279 [a,b] [ 7 ] replicate append |             256 279 [a,b] [ 7 ] replicate append | ||||||
|             280 287 [a,b] [ 8 ] replicate append |             280 287 [a,b] [ 8 ] replicate append | ||||||
|     0 31 [a,b] [ 5 ] replicate  |         ] append-outputs | ||||||
|     2array [ [ length>> [0,b) ] [ ] bi get-table ] map ;     |         0 31 [a,b] [ 5 ] replicate 2array | ||||||
|  |         [ [ length>> [0,b) ] [ ] bi get-table ] map | ||||||
|  |     ] | ||||||
| 
 | 
 | ||||||
| CONSTANT: length-table | CONSTANT: length-table | ||||||
|     { |     { | ||||||
|  | @ -183,10 +179,8 @@ CONSTANT: dist-table | ||||||
|             { 1 [ inflate-static ] } |             { 1 [ inflate-static ] } | ||||||
|             { 2 [ inflate-dynamic ] } |             { 2 [ inflate-dynamic ] } | ||||||
|             { 3 [ bad-zlib-data f ] } |             { 3 [ bad-zlib-data f ] } | ||||||
|         } |         } case | ||||||
|         case |     ] [ produce ] keep call suffix concat ; | ||||||
|     ] |  | ||||||
|     [ produce ] keep call suffix concat ; |  | ||||||
| 
 | 
 | ||||||
| PRIVATE> | PRIVATE> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue