Context algorithm
Semi-predictive context algorithm implementation
 All Data Structures Files Functions Variables Typedefs Macros Pages
alpha.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 "alpha.h"
20 
21 void buildAlpha(Uchar *text, const Uint textlen) {
22  Uint occ[UCHAR_MAX+1] = {0}, i, j;
23  Uchar *tptr;
24 
25  for (tptr = text; tptr < text+textlen; tptr++)
26  {
27  occ[(Uint) *tptr]++;
28  }
29  for (j=0, i=0; i<=UCHAR_MAX; i++)
30  {
31  if(occ[i] > 0)
32  {
33  characters[j++] = (Uchar) i;
34  }
35  }
36  alphasize = j;
37 
38  for(i=0; i<alphasize; i++)
39  {
40  alphaindex[(Uint) characters[i]] = i;
41  }
42 }
void buildAlpha(Uchar *text, const Uint textlen)
Reads input text and initializes alphabet variables.
Definition: alpha.c:21
Uint textlen
Length of the input text in the encoder.
Definition: text.h:23
Uint alphasize
Alphabet size.
Definition: alpha.h:25
unsigned char Uchar
Unsigned char type.
Definition: types.h:48
Uchar * text
Input text to the encoder.
Definition: text.h:26
unsigned long Uint
Unsigned int type.
Definition: types.h:54
Uchar characters[UCHAR_MAX+1]
Characters in text in alphabetical order.
Definition: alpha.h:28
Uint alphaindex[UCHAR_MAX+1]
Index of each alphabet character.
Definition: alpha.h:31