Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Infinite compression: I think I did it!

Name: Anonymous 2014-07-22 7:06

Hello /prog/

I've been experimenting with infinitely efficient compression algorithm. I think I finally got it working. The algorithm quarantees at least one byte reduction of the input.

I've created a reference implementation. It consists of two programs, "pack" and "extract". It's written in C.

Here's a simple demonstration.

C:\> echo Hello
Hello
C:\> echo -n Hello | wc
0 1 5
C:\> echo -n Hello | ./pack | wc
0 1 4
C:\> echo -n Hello | ./pack | ./extract | wc
0 1 5
C:\> echo -n Hello | ./pack | ./extract
HelloC:\>
C:\> echo Hello | ./pack | ./extract
Hello
C:\>


Here's the source code for "pack"
#include <stdio.h>

#define _PACKCALL_ /*
use
standard
conventions */
#define __integer int
#define CHARPTR char*
#define FILE_T FILE*
#define __PACK_SUCCESS 1
#define __PACK_FAILURE__ 1
#define __PACK__SUCCKESS_CODE __integer
#define _PACKER_DATA_TYPE CHARPTR
#define MAIN_SUCCESS_CODE 2

#define \
DO_PACK(data) \
__pack__(data)

#define READ(F) \
fread(__buf, 1, 99999, F) /* TODO buf size? */

#define WRITE(F) \
fwrite(__buf,\
1, __data_len, F\
)

_PACKCALL_ __PACK__SUCCKESS_CODE __pack__(_PACKER_DATA_TYPE __data);

int
main
(
int argc
,char** argv
)
{
FILE_T _file;
int __buf[512];
int _len;
__integer __data_len;
CHARPTR data;
_file = stdin;
_len = READ(_file);
data = __buf;
DO_PACK(data);
__data_len = _len - 1;
WRITE(stdout);

return MAIN_SUCCESS_CODE;
}

_PACKCALL_
__PACK__SUCCKESS_CODE
__pack__
(
_PACKER_DATA_TYPE __data
)
{
//here we define dsl
/* that makes it easier to implement the algorithm
* *
*/
/* dsl is an mini language
* that is suitable for one purpose */
#define Xor(a,b) a^b
#define Fmap(_DAT) \
while( * ptr) \
{ *ptr = F( * ptr);\
++ptr\
; \
}
#define F(_tok) \
Xor(\
_tok\
, X)
__integer X;
CHARPTR _mag = "\x17\x17";

/* FIRST PASS */
X = _mag[0];
CHARPTR ptr = __data;
Fmap(__data);

/* SECOND PASS */
ptr = __data;
X = _mag[1];
Fmap(__data);
}


Check out the __pack__ function for algorithm. It should be pretty straightforward.

Here's the extract.c code
#include <stdio.h>

#define _EXTRACTCALL_ /*
use
standard
conventions */
#define __integer int
#define CHARPTR char*
#define FILE_T FILE*
#define __EXTRACT_SUCCESS 1
#define __EXTRACT_FAILURE__ 1
#define __EXTRACT__SUCCKESS_CODE __integer
#define _EXTRACTER_DATA_TYPE CHARPTR
#define MAIN_SUCCESS_CODE 2

#define \
DO_EXTRACT(data) \
__extract__(data)

#define READ(F) \
fread(__buf+1, 1, 99999, F) /* TODO buf size? */

#define WRITE(F) \
fwrite(__buf+1,\
1, __data_len, F\
)

_EXTRACTCALL_ __EXTRACT__SUCCKESS_CODE __extract__(_EXTRACTER_DATA_TYPE __data);

int
main
(
int arg
,char** argv
)
{
FILE_T _file;
int __buf[512] = {0};
int _len;
__integer __data_len;
CHARPTR data;
_file = stdin;
_len = READ(_file);
data = __buf;
data[0] = _len;
DO_EXTRACT(data);
__data_len = _len + 1;
WRITE(stdout);

return MAIN_SUCCESS_CODE;
}

_EXTRACTCALL_
__EXTRACT__SUCCKESS_CODE
__extract__
(
_EXTRACTER_DATA_TYPE __data
)
{
//here we define mini language
/* that makes it easier to implement the algorithm
*/
#define Xor(a,b) a^b
#define Fmap(_DAT) \
while( * ptr); \
{ *ptr = F( * ptr);\
ptr++\
; \
}
#define F(_tok) \
Xor(\
_tok\
, Y)
char Y;
CHARPTR _rmag = "\x22\x22";
char time(void*);

/* REVERSE SECOND PASS */
Y = _rmag[1];
CHARPTR ptr = __data+1;
Fmap(__data);

/* REVERSE FIRST PASS */
ptr = __data+1;
Y = _rmag[0];
//Fmap(__data);

/* FINALISE */
__data[__data[0] + 4] = time(0);
}


It works the same as pack.c, except it does the opposite.

What I would still need, is some review of the algorithm and implementation code before I take this to my colleagues. I was wondering if some hackers at /prog/ could do this? You'd get your names to computer history book.

Name: Anonymous 2014-07-24 3:49

>>45
The problem with this is that it prohibits the implementation from constructing the error string dynamically. For example, glibc strerror can return an error string that includes the error number ("Unknown error %d"); this is not possible if the return type of strerror is const char *.

The real solution is to provide a means for the error string function to inform the caller of the length of the string beforehand, like sprintf does:

/* Return the length of the error string for the given error number.
* The contents of the error string will be placed in str, provided that it is
* not NULL.
*/
int sprinterr(char *str, int errnum);

/* Lazy example; don't worry about len being negative */

int len;
char *buf;

len = sprinterr(NULL, errno);
buf = malloc(len);
sprinterr(buf, errno);


>>46
I don't grok your distaste for threading in C. If you want to implement a kernel in C, you must use threads. I don't see any good reason to prefer thread unsafe behavior in userspace code just because it's possible to get away with it there.

Name: L. A. Calculus !jYCj6s4P.g 2014-07-24 6:41

>>59

this is not possible if the return type of strerror is const char *.
YES IT IS YA FUKIN RETOID. SEE >>43.

EVEN IF strerror IS REQUIRED 2 NOT MODIFY DA STORAGE POINTED TO BY ANY OF ITS RETURN VALUES AFTER DEY'VE BEEN RETURNED (COMPLETELY DIFFERENT FROM MAKIN DA RETURN TYPE const char *), U CAN STILL RETURN DOSE KINDS OF ERROR STRINGS. U CUD, FOR EXAMPLE, ALLOCATE STORAGE FOR DA STRING, sprintf IT, DEN RETURN A POINTER TO IT. IT'S INEFFICIENT, BUT IT SURE AS FUK IS POSSIBLE.

The real solution is to provide a means for the error string function to inform the caller of the length of the string beforehand, like sprintf does:
sprintf DOESNT DO DAT. YAINT RED DA FUKIN STANDARD, HAV YA?

I don't grok your distaste for threading in C.
DA DAM FAT CATS AT DA ISO WANNA MAKE DA LANGUAGE FAT N BLOATED LIKE C++. MOST PROGRAMS DONT USE THREDS N DONT NEED THRED SAFETY. DA EXAMPLE U LISTED, KERNELS, DON'T REQUIRE THREDS EITHER. DER MAY BE SOME CASES WHERE DEY'RE A GOOD DESIGN OPTION, SURE, BUT 2 SUGGEST DAT U CANNOT WRITE A KERNEL WITHOUT DEM IS SUMFIN A HOT-SHOT YUPPY WUD SAY. JUST COS HTML5'S DA KOOL NEW THING DONT MEAN YA CANT WRITE A FUCKIN WEB PAGE WITHOUT IT.

Name: L. A. Calculus !jYCj6s4P.g 2014-07-24 6:55

IF U GUYS WANT A GOOD SUGGESTION, IT WUD MAKE SENSE 2 IMPLEMENT ERROR STRINGS AS A FORMAT SPECIFIER 4 DA printf FAMILY. DAT WAY U WONT NEED TO CLUTTER DA LANGUAGE WITH EXTRA BULLSHIT, AND IT'S A FUK-LOAD MORE USEFUL THAN DA SHIT U HAD BEFORE. DA PROBLEM U DO GET, THO, IS DAT U BREAK COMPATIBILITY WITH OLDER CODE, SO DA FEATURE WUD BE ABOUT AS USEFUL AS rsize_t. BUT DAT'S NOT TO SAY SOME1 CUDNT REPLACE DA STANDARD C LIBRARY, ENTIRELY, WITH DER OWN CREATION DAT AINT GOVERNED BY A BUNCH OF GREEDY FAT CATS.

SO LET'S CALL IT DA 'r' SPECIFIER. (I THINK PLAN9 USED A SIMILAR METHOD IN DER C LIBRARY, I CANT FUCKIN REMEMBER)

U CAN GET DA LENGTH WITH: snprintf(NULL, 0, "%r", errno)

COPY WITH: sprintf(buf, "%r", errno);

HALF DA TIME U JUST WRITE DESE FUCKIN ERROR MESSAGES TO stderr THO, SO U CUD JUST DO:

fprintf(stderr, "%s: %r\n", program_name, errno);

U WONT EVEN NEED A FUCKIN strerror/perror FUNCTION ANYMORE.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List