• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  **	Filename:    adaptive.h
3  **	Purpose:     Interface to adaptive matcher.
4  **	Author:      Dan Johnson
5  **	History:     Fri Mar  8 10:00:49 1991, DSJ, Created.
6  **
7  **	(c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 #ifndef ADAPTIVE_H
19 #define ADAPTIVE_H
20 
21 /**----------------------------------------------------------------------------
22           Include Files and Type Defines
23 ----------------------------------------------------------------------------**/
24 #include "oldlist.h"
25 #include "intproto.h"
26 #include <stdio.h>
27 
28 typedef struct
29 {
30   uinT16 ProtoId;
31   uinT16 dummy;
32   PROTO_STRUCT Proto;
33 }
34 
35 
36 TEMP_PROTO_STRUCT;
37 typedef TEMP_PROTO_STRUCT *TEMP_PROTO;
38 
39 typedef struct
40 {
41   uinT8 NumTimesSeen;
42   uinT8 ProtoVectorSize;
43   PROTO_ID MaxProtoId;
44   LIST ContextsSeen;
45   BIT_VECTOR Protos;
46 } TEMP_CONFIG_STRUCT;
47 typedef TEMP_CONFIG_STRUCT *TEMP_CONFIG;
48 
49 typedef UNICHAR_ID *PERM_CONFIG;
50 
51 typedef union
52 {
53   TEMP_CONFIG Temp;
54   PERM_CONFIG Perm;
55 } ADAPTED_CONFIG;
56 
57 typedef struct
58 {
59   uinT8 NumPermConfigs;
60   uinT8 dummy[3];
61   BIT_VECTOR PermProtos;
62   BIT_VECTOR PermConfigs;
63   LIST TempProtos;
64   ADAPTED_CONFIG Config[MAX_NUM_CONFIGS];
65 } ADAPT_CLASS_STRUCT;
66 typedef ADAPT_CLASS_STRUCT *ADAPT_CLASS;
67 
68 typedef struct
69 {
70   INT_TEMPLATES Templates;
71   int NumNonEmptyClasses;
72   uinT8 NumPermClasses;
73   uinT8 dummy[3];
74   ADAPT_CLASS Class[MAX_NUM_CLASSES];
75 } ADAPT_TEMPLATES_STRUCT;
76 typedef ADAPT_TEMPLATES_STRUCT *ADAPT_TEMPLATES;
77 
78 /**----------------------------------------------------------------------------
79           Public Function Prototypes
80 ----------------------------------------------------------------------------**/
81 #define NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses)
82 
83 #define IsEmptyAdaptedClass(Class) ((Class)->NumPermConfigs == 0 &&      \
84 (Class)->TempProtos == NIL)
85 
86 #define ConfigIsPermanent(Class,ConfigId)		\
87 (test_bit ((Class)->PermConfigs, ConfigId))
88 
89 #define MakeConfigPermanent(Class,ConfigId)	\
90 (SET_BIT ((Class)->PermConfigs, ConfigId))
91 
92 #define MakeProtoPermanent(Class,ProtoId)	\
93 (SET_BIT ((Class)->PermProtos, ProtoId))
94 
95 #define TempConfigFor(Class,ConfigId)	\
96 ((Class)->Config[ConfigId].Temp)
97 
98 #define PermConfigFor(Class,ConfigId)	\
99 ((Class)->Config[ConfigId].Perm)
100 
101 #define IncreaseConfidence(TempConfig)	\
102 ((TempConfig)->NumTimesSeen++)
103 
104 void AddAdaptedClass(ADAPT_TEMPLATES Templates,
105                     ADAPT_CLASS Class,
106                     CLASS_ID ClassId);
107 
108 void FreeTempProto(void *arg);
109 
110 void FreeTempConfig(TEMP_CONFIG Config);
111 
112 ADAPT_CLASS NewAdaptedClass();
113 
114 void free_adapted_class(ADAPT_CLASS adapt_class);
115 
116 void free_adapted_templates(ADAPT_TEMPLATES templates);
117 
118 TEMP_CONFIG NewTempConfig(int MaxProtoId);
119 
120 TEMP_PROTO NewTempProto();
121 
122 ADAPT_CLASS ReadAdaptedClass(FILE *File);
123 
124 PERM_CONFIG ReadPermConfig(FILE *File);
125 
126 TEMP_CONFIG ReadTempConfig(FILE *File);
127 
128 void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs);
129 
130 void WritePermConfig(FILE *File, PERM_CONFIG Config);
131 
132 void WriteTempConfig(FILE *File, TEMP_CONFIG Config);
133 
134 #endif
135