This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.hafthor; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| public class Main { | |
| public static void main(final String[] args) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.hafthor; | |
| public class Main { | |
| public static void main(final String[] args) { | |
| Nonogram n = new Nonogram("1 3 9 122 42 42 122 9 3 1", "33 22 8 121 121 6 22 11 6 4"); // 9 | |
| while(n.solve()) n.print(); | |
| n.print(); | |
| } | |
| public static class Nonogram { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.hafthor; | |
| public class Main { | |
| public static void main(final String[] args) { | |
| final String input = "" + | |
| "89. .5. ..." + | |
| "2.. 7.9 ..." + | |
| "..4 ..3 ..." + | |
| "..9 6.2 ..3" + | |
| "... ..1 897" + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const static unsigned char LENGTH_CODE_EXTRA_BITS[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; | |
| const static unsigned char DISTANCE_CODE_EXTRA_BITS[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; | |
| const static unsigned char CODE_LENGTHS_ORDER[] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; | |
| static unsigned short LENGTH_CODE[sizeof(LENGTH_CODE_EXTRA_BITS)]; | |
| static unsigned short DISTANCE_CODE[sizeof(DISTANCE_CODE_EXTRA_BITS)]; | |
| static unsigned char BIT_REVERSE[256]; | |
| const static unsigned int BLOCK_END = 256; | |
| const static unsigned char READ_BITS_FOR_CODE[]={2,3,7}, ADD_COUNT_FOR_CODE[]={3,3,11}; | |
| static short HUFFTREE_LITLEN[(1 << 24)+1]; | |
| static short HUFFTREE_DIST[(1 << 24)+1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub struct Inflatey { | |
| input: Vec<u8>, | |
| output: Vec<u8>, | |
| input_bit_pos: usize, | |
| output_pos: usize, | |
| length_code: [u16; 29], | |
| distance_code: [u16; 30], | |
| bit_reverse: [u8; 256], | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace SlowInflate { | |
| #pragma warning disable IDE0044 // Add readonly modifier | |
| public class Inflatey { | |
| private byte[] input, output; | |
| public uint inputBitPos, outputPos; | |
| private static byte[] LENGTH_CODE_EXTRA_BITS = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; | |
| private static byte[] DISTANCE_CODE_EXTRA_BITS = new byte[] { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "errors" | |
| "fmt" | |
| "io" | |
| "os" | |
| "time" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // to use | |
| // const inflatey = require('./inflatey'), fs = require('fs'); | |
| // const buf = fs.readFileSync('somefile.gz'); | |
| // const size = buf[buf.length-1]*16777216+buf[buf.length-2]*65536+buf[buf.length-3]*256+buf[buf.length-4]; | |
| // const out = new Uint8Array(size); | |
| // const infl = new inflatey(buf, out); | |
| // infl.inputBitPos(80); // skip gz header bits | |
| // infl.inflate(); | |
| // fs.writeFileSync('somefile', out); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.hafthor; | |
| import java.util.Arrays; | |
| public class SlowInflate { | |
| public static void main(final String[] args) { | |
| fixed(); | |
| fixedBetter(); | |
| dynamic(); | |
| stored(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // instead of | |
| source.parallelStream().forEachOrdered(v -> ...); | |
| // which is ordered, but not parallel | |
| // or | |
| source.parallelStream().forEach(v -> ...); | |
| // which is parallel, but unordered | |
| // do this | |
| final var sourceQueue = new ConcurrentQueue<>(source); | |
| source.parallelStream().forEach(dummy -> { final var v = sourceQueue.poll(); ... } |