Menu

[1626c5]: / joe / cclass.h  Maximize  Restore  History

Download this file

126 lines (97 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Character classes
* Copyright
* (C) 2015 Joseph H. Allen
*
* This file is part of JOE (Joe's Own Editor)
*/
/* An interval. A character matches if it's in the range.
An array of these can be used to define a character class. */
struct interval {
int first;
int last;
};
/* Sort an struct interval array */
void interval_sort(struct interval *array, ptrdiff_t size);
/* Test if character is in a sorted interval array using binary search.
Returns -1 if not found, or index to matching struct interval */
ptrdiff_t interval_test(struct interval *array, ptrdiff_t size, int ch);
/* A character class implemented as a radix tree
These structures are also used for character maps based
on radix trees: see cmap.h */
#define LEAFSIZE 16
#define LEAFMASK 0xF
#define LEAFSHIFT 0
#define THIRDSIZE 32
#define THIRDMASK 0x1f
#define THIRDSHIFT 4
#define SECONDSIZE 32
#define SECONDMASK 0x1f
#define SECONDSHIFT 9
#define TOPSIZE 68
#define TOPMASK 0x7f
#define TOPSHIFT 14
struct First {
short entry[68];
};
struct Mid {
short entry[32];
};
struct Leaf {
void *entry[16];
};
struct Level {
int alloc;
int size;
union {
struct Mid *b;
struct Mid *c;
struct Leaf *d;
} table;
};
struct Rset {
int flag;
struct First top;
struct Level second;
struct Mid mid;
struct Level third;
};
void rset_init(struct Rset *r);
void rset_clr(struct Rset *r);
int rset_lookup(struct Rset *r, int ch);
int rset_lookup_unopt(struct Rset *r, int ch);
void rset_add(struct Rset *r, int ch, int che);
void rset_opt(struct Rset *r);
void rset_set(struct Rset *r, struct interval *array, ptrdiff_t size);
void rset_show(struct Rset *r);
/* A character class */
struct Cclass {
ptrdiff_t size; /* Malloc size of intervals */
ptrdiff_t len; /* Number of entries in intervals */
struct interval *intervals; /* sorted, non-overlapping, non-adjacent */
struct Rset rset[1]; /* Radix tree version of character class */
};
/* Initialize a character class */
void cclass_init(struct Cclass *cclass);
/* Free memory used by a Cclass (does not free cclass itself) */
void cclass_clr(struct Cclass *cclass);
/* Add a range to a character class */
void cclass_add(struct Cclass *cclass, int first, int last);
/* Remove a range to a character class */
void cclass_sub(struct Cclass *cclass, int first, int last);
/* Merge one character class into another */
void cclass_union(struct Cclass *cclass, struct Cclass *n);
void cclass_merge(struct Cclass *cclass, struct interval *intervals, int len);
/* Subtract one character class from another */
void cclass_diff(struct Cclass *cclass, struct Cclass *n);
/* Compute inverse of a character class */
void cclass_inv(struct Cclass *cclass);
/* Lookup a character in a character class using binary search.
Return true if character is in the class. */
int cclass_lookup_unopt(struct Cclass *m, int ch);
/* Optimize a character class for fast lookup with cclass_lookup. Generates a radix tree
version of the character class. */
void cclass_opt(struct Cclass *cclass);
/* Return true if character is in the class */
int cclass_lookup(struct Cclass *cclass, int ch);
void cclass_show(struct Cclass *cclass);
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.