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: L. A. Calculus !jYCj6s4P.g 2014-07-23 6:26

But each error has different length in the str form
SO IN A TYPICAL SCENARIO U'D CHEK DA LENGTH, ALLOCATE A BUFFER OF DA CORRECT SIZE, DEN CALL strerror_s(buffer, errcode). NO NEED 2 PASS A MAXIMUM SIZE TO strerror_s. U ALREADY KNOW HOW MANY BYTES IT'LL COPY, N IT CAN GO AHED N COPY EM WITHOUT HAVIN 2 ENSURE DAT IT DOESN'T EXCEED DA SIZE U PASSED. SIMPLER 4 DA CALLER (PROVIDING DEY ARENT RETOIDS WHO LIKE TRUNCATED ERROR MESSAGES), SIMPLER 4 DA IMPLEMENTER. OF COURSE IT'S SIMPLEST JUST 2 USE strerror.

DER'S REALLY LITTLE DIFFERENCE BETWEEN:

char *s = strerror(errno);
AND
const char *s = strerror(errno);

UR FUCKED IF U MODIFY *s IN EITHER CASE. UNDEFINED BEHAVIOUR IF DA STORAGE POINTED TO BY strerror's RETURN VALUE IS MODIFIED. UNDEFINED BEHAVIOUR IF U MODIFY ANY STORAGE WITH A const-QUALIFIED TYPE. IF strerror RETURNED A const char *, DA FIRST EXAMPLE WUD REQUIRE A CAST. DAT'S DA ONLY DIFFERENCE.

Name: Anonymous 2014-07-23 6:49

>>41
Yes, you are right about strerror_s getting 3 arguments

UR FUCKED IF U MODIFY *s IN EITHER CASE. UNDEFINED BEHAVIOUR IF DA STORAGE POINTED TO BY strerror's RETURN VALUE IS MODIFIED. UNDEFINED BEHAVIOUR IF U MODIFY ANY STORAGE WITH A const-QUALIFIED TYPE. IF strerror RETURNED A const char *, DA FIRST EXAMPLE WUD REQUIRE A CAST. DAT'S DA ONLY DIFFERENCE.
The difference is that if strerror returns a char * it usualy uses a static array and modifies the buffer, unlike the const char * where it would not have the need to do that

Name: L. A. Calculus !jYCj6s4P.g 2014-07-23 7:10

>>42
The difference is that if strerror returns a char * it usualy uses a static array and modifies the buffer, unlike the const char * where it would not have the need to do that
DER'S NO PROBLEM WITH RETURNING A const char * OR A char * IN EITHER CASE.

const char *strerror_nextstandard(int e)
OR
char *strerror(int e)
{
extern const char *_error_message[];
static char s[80];

if (e >= 0 && e < NERRORS)
return (char *) _error_message[e];
sprintf(s, "invalid error code: %d", e);
return s;
}

Name: L. A. Calculus !jYCj6s4P.g 2014-07-23 7:29

CALLER'S CODE WUD LOOK SOMETHING LIKE DIS:

char *a;
const char *b;

a = strerror(errno);
a = (char *) strerror_nextstandard(errno);
b = strerror(errno);
b = strerror_nextstandard(errno);


U CUD BASICALLY USE ANY ONE U WANT. DA const QUALIFIER IN strerror_nextstandard SEEMED 2 BE DA ONLY DIFFERENCE FROM strerror IN UR PROPOSITION. DA STORAGE POINTED TO BY DA RETURN VALUE OF strerror IS ALREADY IMMUTABLE (MODIFYING IT HAS UNDEFINED BEHAVIOUR) ALTHOUGH U CUD ARGUE DAT char * DOESNT MAKE DAT OBVIOUS. EITHER WAY IT AIN'T ALL DAT SIGNIFICANT. MAIN ARGUMENT FOR const-QUALIFIED RETURN TYPE IS DAT IT MAKES IT OBVIOUS DAT IT SHUDN'T BE MODIFIED BY DA CALLER. MAIN ARGUMENT FOR UNQUALIFIED RETURN TYPE IS DAT IT PLAYS NICE WITH QUALIFIED AND UNQUALIFIED VERSIONS OF DA SAME TYPE (DOESNT NEED A CAST).

Name: Anonymous 2014-07-23 7:36

>>44
The strerror_nextstandard (as I defined it) does not change the buffer that's returned
a = strerror(errno);
/* something that changes errno */
b = strerror(errno);

in that case the value pointed by a may have been changed by strerror, unlike my strerror_nextstandard where it does not return a static buffer

Name: L. A. Calculus !jYCj6s4P.g 2014-07-23 7:37

O, I THINK I GET DA POINT OF UR strerror_nextstandard NOW. IT AIN'T RELEVANT TO DA RETURN TYPE, BUT U'D ESSENTIALLY REQUIRE DAT DA STORAGE POINTED 2 BY strerror'S RETURN VALUE IS NOT MODIFIED BY SUBSEQUENT CALLS 2 strerror.

U DAMN YUPPIES R ALWAYS THINKIN ABOUT UR THREDS!

Name: Anonymous 2014-07-23 7:58

Yes, sorry for not being clean. I also made the horrible assumation that you are able to change the returned value of strerror and the reason because it returns char * is this

Name: Anonymous 2014-07-23 8:08

What would you use instead of threads then?

Name: Anonymous 2014-07-23 8:41

>>48
IN WAT SITUATION WUD U CONSIDER USING THREDS? OR DO U JUST RANDOMLY USE DEM IN ALL UR PROGRAMS?

Name: Anonymous 2014-07-23 8:45

>>49
In a program like a http server where I have to serve multiple people at the same time

Name: L. A. Calculus !jYCj6s4P.g 2014-07-23 8:59

>>50
U CUD USE fork, OR IF U WANT TO KEEP IT IN ONE PROCESS, U CUD USE select

Name: Anonymous 2014-07-23 9:03

>>51
fork is more expencive and select can't make it parallel

Name: L. A. Calculus !jYCj6s4P.g 2014-07-23 9:05

>>52
select can't make it parallel
WAT?

Name: Anonymous 2014-07-23 15:02

multithreading < multiprocessing

Name: Anonymous 2014-07-23 19:52

Name: L. A. Calculus !jYCj6s4P.g 2014-07-23 20:35

2 EAT DA POOPOO????!?!??

Name: Anonymous 2014-07-24 1:06

Unlimited Compression Works

Name: Anonymous 2014-07-24 1:32

i'm the java of my app

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: Anonymous 2014-07-24 5:15

>>59
Inderesting example, so something like strerror_s is the future

Name: Anonymous 2014-07-24 5:49

/* const */ char *
strerror (int error)
{
const char err[numberoferrors][sizeofbiggesterror] = {
"No error",
"Unknown error %d",
[EDOM] = "NiggerDicks",
[EILSEQ] = "KIKES",
[ERANGE] = "Sarah Steingold"
};
static _Thread_local char buf[sizeofbiggesterror + maxcharactersaintcanhave];
sprintf (buf, err[error < 0 || error < numberoferrors ? err[error] : err[1]],
error);
return buf;
}

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.

Name: Anonymous 2014-07-24 7:05

>>63
Why not suggest it to the committee? It's a nice idea.

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

>>64
COS DEYRE HYENAS WHO WANNA RUIN DA LANGUAGE DEANIS RICKY LOVED

Name: Anonymous 2014-07-24 7:16

>>65
If you don't send your idea to them, then I will do it, and I will send it exacly as you wrote it (with the uppercase everywhere)

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

>>66
I LOOK FORWARD TO DA REEDING DA RESPONSE DEY GIVE U. SOMETHIN ALONG DA LINES OF "PLEEZ FORWARD DIS REQUEST 2 DA C++ COMMITTEE: NOWADAYS WE JUST COPY DER CHANGES"

Name: L. A. Calculus !jYCj6s4P.g 2014-07-24 7:32

>>66
N IF U TAKE DER ADVICE DA C++ COMMITTEE WILL RESPOND WITH: "WAT DA FUCK DOES DIS HAV 2 DO WITH OOP, POLYMOOFISM, OR MICROSOFT FUCKIN SAM? N DEN DEY'LL LAUGH AT U WEN U SAY U CAME FROM DA C COMMITTEE AND DEY'LL TELL U TO COME BACK WHEN U PUT A FEW THOUSAND PAGES ON UR FUCKIN STANDARD.

Name: L. A. Calculus !jYCj6s4P.g 2014-07-24 7:37

IT'S ALL FUCKIN POLITICS. DA C COMMITTEE MAKES DER LANGUAGE FAT N BLOATED TO TRY N GAIN ACCEPTANCE OF DA C++ COMMITTEE. MEANWHILE DA C++ COMMITTEE ARE SHOVIN LIVING CATS N DOGS INTO DER STANDARD LIKE TARRARE IN AN ANIMAL SHELTER. IT AINT GONNA STOP TILL DA FAT CATS IN DA C COMMITTEE GET SCARED N GO ON A FUCKIN DIET AS A RESULT OF DA C++ COMMITTEE DYING OF A FUCKIN HEART ATTACK.

Name: Anonymous 2014-07-24 8:24

Sadly I may have to agree, some nice things were added in C11 and C99 but they filled them with shit
(example: // comments, *_s niggering, etc)

Name: Anonymous 2014-07-24 12:34

>>70
what are you talking about?

Name: Anonymous 2014-07-24 16:50

>>59,62,63
IF U GUYS WANT A GOOD SUGGESTION, IT WUD MAKE SENSE 2 IMPLEMENT ERROR STRINGS AS A FORMAT SPECIFIER 4 DA printf FAMILY.

s/sprintf/snprintf/

We are proposing nearly the same thing, then. glibc already has something close - it allows you to use 'm' as a conversion specifier to get the error string for the current value of errno. Yours is obviously better since it allows printing values other than the one in errno.

DA PROBLEM U DO GET, THO, IS DAT U BREAK COMPATIBILITY WITH OLDER CODE

Only if the older code expects that format strings containing the new conversion specifier will be printed verbatim. Most existing code will hopefully use the '%' conversion specifier where a literal '%' is expected in the output. In practice you already can't rely on implementations not defining nonstandard conversion specifiers.

New code can just check __STDC_VERSION__.

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.

And saying threads are a special case is something a curmudgeon would say. Today SMP is the norm nearly everywhere.

Name: Anonymous 2014-08-26 9:42

Name: Anonymous 2014-08-26 10:16

>>6,17,19,36,39,41,43-44,46,51,53,56,62,65,67-69
go back to le /g/, smelly neckbeard

Name: Anonymous 2014-08-26 13:39

>>1
GNU quality code!

Name: Anonymous 2014-09-04 9:18

hax my anus

Name: Anonymous 2014-09-04 20:56

my feaces is compressed so can easily travel through sewage network

Name: Anonymous 2014-09-04 21:09

>>77
Don't compress it too much! It'll be stiff and get lodged somewhere!

Name: Anonymous 2014-09-05 1:22

I made my fortune by pooing diamonds.

Name: Anonymous 2014-09-05 3:01

>>78

Usually it gets lodged into my own anus, sadly.

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