File src/hstr_history.c changed (mode: 100644) (index 2b1dd4e..acae663) |
... |
... |
static const char *commandBlacklist[] = { |
36 |
36 |
#define DEBUG_RADIXSORT() |
#define DEBUG_RADIXSORT() |
37 |
37 |
#endif |
#endif |
38 |
38 |
|
|
|
39 |
|
// TODO make this configurable from command line as option |
|
40 |
|
#define METRICS_LOGARITHM(RANK,ORDER,LENGTH) RANK+(log(ORDER)*10.0)+LENGTH |
|
41 |
|
#define METRICS_ADDITIVE(RANK,ORDER,LENGTH) RANK+ORDER/10+LENGTH |
|
42 |
|
|
39 |
43 |
unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) { |
unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) { |
40 |
|
long metrics=rank+(log(newOccurenceOrder)*10.0)+length; |
|
41 |
|
// alternative metrics: |
|
42 |
|
// rank+newOccurenceOrder/10+length |
|
|
44 |
|
long metrics=METRICS_LOGARITHM(rank, newOccurenceOrder, length); |
43 |
45 |
assert(metrics<UINT_MAX); |
assert(metrics<UINT_MAX); |
44 |
46 |
return metrics; |
return metrics; |
45 |
47 |
} |
} |
|
... |
... |
HistoryItems *get_prioritized_history() |
123 |
125 |
RadixItem *radixItem; |
RadixItem *radixItem; |
124 |
126 |
HIST_ENTRY **historyList=history_list(); |
HIST_ENTRY **historyList=history_list(); |
125 |
127 |
char **rawHistory=malloc(sizeof(char*) * historyState->length); |
char **rawHistory=malloc(sizeof(char*) * historyState->length); |
126 |
|
int rawOffset=historyState->length-1; |
|
|
128 |
|
int rawOffset=historyState->length-1, rawTimestamps=0; |
127 |
129 |
char *line; |
char *line; |
128 |
130 |
for(i=0; i<historyState->length; i++, rawOffset--) { |
for(i=0; i<historyState->length; i++, rawOffset--) { |
129 |
131 |
if(!regexp_match(®exp, historyList[i]->line)) { |
if(!regexp_match(®exp, historyList[i]->line)) { |
|
132 |
|
rawHistory[rawOffset]=0; |
|
133 |
|
rawTimestamps++; |
130 |
134 |
continue; |
continue; |
131 |
135 |
} |
} |
132 |
136 |
if(historyList[i]->line && strlen(historyList[i]->line)>itemOffset) { |
if(historyList[i]->line && strlen(historyList[i]->line)>itemOffset) { |
|
... |
... |
HistoryItems *get_prioritized_history() |
162 |
166 |
} |
} |
163 |
167 |
} |
} |
164 |
168 |
} |
} |
|
169 |
|
if(rawTimestamps) { |
|
170 |
|
rawOffset=0; |
|
171 |
|
for(i=0; i<historyState->length; i++) { |
|
172 |
|
if(rawHistory[i]) { |
|
173 |
|
rawHistory[rawOffset++]=rawHistory[i]; |
|
174 |
|
} |
|
175 |
|
} |
|
176 |
|
} |
165 |
177 |
|
|
166 |
178 |
regfree(®exp); |
regfree(®exp); |
167 |
179 |
|
|
|
... |
... |
HistoryItems *get_prioritized_history() |
170 |
182 |
RadixItem **prioritizedRadix=radixsort_dump(&rs); |
RadixItem **prioritizedRadix=radixsort_dump(&rs); |
171 |
183 |
prioritizedHistory=malloc(sizeof(HistoryItems)); |
prioritizedHistory=malloc(sizeof(HistoryItems)); |
172 |
184 |
prioritizedHistory->count=rs.size; |
prioritizedHistory->count=rs.size; |
173 |
|
prioritizedHistory->rawCount=historyState->length; |
|
|
185 |
|
prioritizedHistory->rawCount=historyState->length-rawTimestamps; |
174 |
186 |
prioritizedHistory->items=malloc(rs.size * sizeof(char*)); |
prioritizedHistory->items=malloc(rs.size * sizeof(char*)); |
175 |
187 |
prioritizedHistory->rawItems=rawHistory; |
prioritizedHistory->rawItems=rawHistory; |
176 |
188 |
for(i=0; i<rs.size; i++) { |
for(i=0; i<rs.size; i++) { |