Context algorithm
Semi-predictive context algorithm implementation
 All Data Structures Files Functions Variables Typedefs Macros Pages
statistics.c
Go to the documentation of this file.
1 /* Copyright 2013 Jorge Merlino
2 
3  This file is part of Context.
4 
5  Context is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Context is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Context. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "statistics.h"
20 #include "alpha.h"
21 #include "spacedef.h"
22 #include "stack.h"
23 
24 static Uint stacktop=0, stackalloc=0, *stack = NULL;
25 
30  statistics_t st;
31 
32  CALLOC(st, struct statistics, 1);
33  CALLOC(st->count, Uint, alphasize);
35  return st;
36 }
37 
38 
43  FREE(st->count);
44  FREE(st->symbols);
45  FREE(st);
46 }
47 
52  Uint statsPtr;
53 
54  if (NOTSTACKEMPTY) {
55  POPNODE(statsPtr);
56  return (statistics_t)statsPtr;
57  }
58  else {
59  return allocStatistics();
60  }
61 }
62 
67  memset(st->count, 0, alphasize * sizeof(Uint));
68  memset(st->symbols, 0, alphasize * sizeof(Uchar));
69  st->symbolCount = 0;
70  st->cost = 0;
71  PUSHNODE((Uint)st);
72 }
73 
74 void freeBuffer() {
75  Uint statsPtr;
76 
77  while (NOTSTACKEMPTY) {
78  POPNODE(statsPtr);
79  freeStatistics((statistics_t)statsPtr);
80  }
81  FREE(stack);
82  stacktop = stackalloc = 0;
83 }
Uint * count
List with the number of occurrences of each character in this state.
Definition: statistics.h:26
void freeBuffer()
Deletes all statistics stored in the buffer.
Definition: statistics.c:74
Uint alphasize
Alphabet size.
Definition: alpha.h:25
unsigned char Uchar
Unsigned char type.
Definition: types.h:48
double cost
Cost assigned to this subtree.
Definition: statistics.h:29
#define POPNODE(N)
Pops an element out of the stack.
Definition: stack.h:51
#define FREE(P)
Frees a block of memory and makes the pointer NULL.
Definition: spacedef.h:58
#define CALLOC(S, T, N)
Allocs a new block of memory and sets all its bits to zero.
Definition: spacedef.h:72
unsigned long Uint
Unsigned int type.
Definition: types.h:54
Uint symbolCount
Number of occuring symbols.
Definition: statistics.h:28
statistics_t getStatistics()
Returns a new statistics structure, can be created or obtained from the buffer.
Definition: statistics.c:51
statistics_t allocStatistics()
Creates and initializes a new statistics structure instance.
Definition: statistics.c:29
static Uint * stack
Definition: statistics.c:24
static Uint stackalloc
Definition: statistics.c:24
static Uint stacktop
Definition: statistics.c:24
Structure that saves statistics for each tree node in the encoder.
Definition: statistics.h:25
void returnStatistics(statistics_t st)
Puts a statistics structure that is no longer used into the buffer.
Definition: statistics.c:66
void freeStatistics(statistics_t st)
Deletes a statistics structure instance.
Definition: statistics.c:42
Uchar * symbols
List of occuring symbols.
Definition: statistics.h:27
#define NOTSTACKEMPTY
Indicates if the stack is empty.
Definition: stack.h:30
#define PUSHNODE(N)
Pushes a new item to the stack.
Definition: stack.h:37