Context algorithm
Semi-predictive context algorithm implementation
 All Data Structures Files Functions Variables Typedefs Macros Pages
reverse.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 "types.h"
20 
25 void reverseinplace(Uchar *s,Uint len) {
26  Uchar *front, *back, tmp;
27 
28  for(front = s, back = s + len - 1; front < back; front++, back--) {
29  tmp = *front;
30  *front = *back;
31  *back = tmp;
32  }
33 }
34 
35 
41 void reversestring(Uchar *s, Uint len, Uchar *sreverse) {
42  Uchar *sp;
43  Uint pos;
44 
45  for(pos = 0, sreverse += len-1, sp = s; pos < len; *sreverse-- = *sp++, pos++);
46  sreverse++;
47 }
48 
49 
56 void reverseString2Binary(Uchar *s, Uint len, Uchar *sreverse, Uint revLength) {
57  char ch;
58  int pos, i;
59 
60  for(pos = 0, sreverse += revLength-1; pos != len; s++, pos++){
61  ch = *s;
62  for (i = 0; i < 8; i++) {
63  *sreverse-- = ((ch & 0x80) >> 7 ? '1' : '0');
64  ch = ch << 1;
65  }
66  }
67 }
void reverseinplace(Uchar *s, Uint len)
Reverses a string without using extra memory.
Definition: reverse.c:25
void reverseString2Binary(Uchar *s, Uint len, Uchar *sreverse, Uint revLength)
Reverses a string bit by bit and returns a new bit string with the reversed bits. ...
Definition: reverse.c:56
unsigned char Uchar
Unsigned char type.
Definition: types.h:48
void reversestring(Uchar *s, Uint len, Uchar *sreverse)
Reverses a string and returns the reverse in a new string.
Definition: reverse.c:41
unsigned long Uint
Unsigned int type.
Definition: types.h:54
static short pos
Current position in the buffer.
Definition: fsmTree.c:35