209 assert(ret >= 0 &&
"out of memory");
211 if (
s->size <
s->len + 1) {
214 assert(
s->size != 0 &&
"overflow");
215 }
while (
s->size <
s->len + 1);
238 return ((
size_t)((syms - 1) >> 1) * ((syms - 2) >> 1) +
239 (left >> 1) - 1) * (
g.max - 1) +
245 if (
g.done !=
NULL) {
246 for (
size_t n = 0;
n <
g.size;
n++)
267 assert(syms > left && left > 0 &&
len <
g.max);
270 size_t index =
map(syms, left,
len);
277 int least = (left << 1) - syms;
284 int most = (((
code_t)left << (
g.max -
len)) - syms) /
289 for (
int use = least; use <= most; use++) {
290 got =
count(syms - use, (left - use) << 1,
len + 1);
292 if (got == (
big_t)-1 || sum < got)
310 size_t index =
map(syms, left,
len);
319 size_t length =
g.done[index].len;
370 rem = 1 << (
len -
g.root);
376 if (
mem >=
g.large) {
388 syms +=
g.code[
bits];
389 left -=
g.code[
bits];
396 syms,
g.root + 1, ((1 <<
g.root) - left) << 1);
414 int least = (left << 1) - syms;
421 int most = (((
code_t)left << (
g.max -
len)) - syms) /
428 rem = 1 << (
len -
g.root);
434 for (use = least; use <= most; use++) {
436 examine(syms - use, (left - use) << 1,
len + 1,
437 mem + (rem ? 1 << (
len -
g.root) : 0), rem << 1);
439 rem = 1 << (
len -
g.root);
456 for (
int n = 0;
n <=
g.max;
n++)
461 g.large = 1 <<
g.root;
463 for (
int n = 3;
n <= syms;
n++)
464 for (
int left = 2; left <
n; left += 2) {
467 size_t index =
map(
n, left,
g.root + 1);
468 if (
g.root + 1 <
g.max &&
g.num[index])
473 if (
g.num[index - 1] &&
n <= left << 1)
474 examine((
n - left) << 1, (
n - left) << 1,
g.root + 1,
479 printf(
"maximum of %d table entries for root = %d\n",
g.large,
g.root);
480 fputs(
g.out.str, stdout);
510 syms = atoi(
argv[1]);
512 g.root = atoi(
argv[2]);
514 g.max = atoi(
argv[3]);
517 if (argc > 4 || syms < 2 ||
g.root < 1 ||
g.max < 1) {
518 fputs(
"invalid arguments, need: [sym >= 2 [root >= 1 [max >= 1]]]\n",
524 if (
g.max > syms - 1)
529 for (
code_t word = 1; word; word <<= 1)
534 fputs(
"abort: code length too long for internal types\n", stderr);
540 fprintf(stderr,
"%d symbols cannot be coded in %d bits\n",
546 g.code =
calloc(
g.max + 1,
sizeof(
int));
555 int n = (syms - 1) >> 1;
556 assert(
g.size <= (
size_t)-1 /
n &&
"overflow");
559 assert(
g.size <= (
size_t)-1 /
n &&
"overflow");
567 for (
int n = 2;
n <= syms;
n++) {
570 assert(got != (
big_t)-1 && sum >= got &&
"overflow");
572 printf(
"%"PRIbig" total codes for 2 to %d symbols", sum, syms);
573 if (
g.max < syms - 1)
574 printf(
" (%d-bit length limit)\n",
g.max);
576 puts(
" (no length limit)");
592 fputs(
"cannot handle minimum code lengths > root", stderr);
int bits(struct state *s, int need)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec vector
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
void string_free(string_t *s)
void examine(int syms, int left, int len, int mem, int rem)
void string_printf(string_t *s, char *fmt,...)
int main(int argc, char **argv)
big_t count(int syms, int left, int len)
void string_init(string_t *s)
int been_here(int syms, int left, int len, int mem, int rem)
size_t map(int syms, int left, int len)
void string_clear(string_t *s)
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
assert(limit<=UINT32_MAX/2)