File src/hstr_history.c changed (mode: 100644) (index 1ba72e7..6a9e329) |
8 |
8 |
*/ |
*/ |
9 |
9 |
|
|
10 |
10 |
#include <stdio.h> |
#include <stdio.h> |
|
11 |
|
#include <limits.h> |
11 |
12 |
#include <readline/history.h> |
#include <readline/history.h> |
12 |
13 |
#include "include/hstr_history.h" |
#include "include/hstr_history.h" |
13 |
14 |
|
|
|
... |
... |
static const char *commandBlacklist[] = {"ls", "pwd", "cd", "hh", "mc"}; |
30 |
31 |
#define DEBUG_RADIXSORT() |
#define DEBUG_RADIXSORT() |
31 |
32 |
#endif |
#endif |
32 |
33 |
|
|
33 |
|
#define HISTORY_RANKING_FUNCTION(RANK,NEWOCCURENCEORDER,LNG) RANK+NEWOCCURENCEORDER/10+LNG |
|
|
34 |
|
unsigned history_ranking_function(unsigned rank, int newOccurenceOrder, size_t length) { |
|
35 |
|
long metrics=rank+newOccurenceOrder/10+length; |
|
36 |
|
assert(metrics<UINT_MAX); |
|
37 |
|
return metrics; |
|
38 |
|
} |
34 |
39 |
|
|
35 |
40 |
char *get_history_file_name() |
char *get_history_file_name() |
36 |
41 |
{ |
{ |
|
... |
... |
HistoryItems *get_prioritized_history() |
96 |
101 |
} |
} |
97 |
102 |
if((r=hashset_get(&rankmap, line))==NULL) { |
if((r=hashset_get(&rankmap, line))==NULL) { |
98 |
103 |
r=malloc(sizeof(RankedHistoryItem)); |
r=malloc(sizeof(RankedHistoryItem)); |
99 |
|
r->rank=HISTORY_RANKING_FUNCTION(0, i, strlen(line)); |
|
|
104 |
|
r->rank=history_ranking_function(0, i, strlen(line)); |
100 |
105 |
r->item=historyList[i]->line; |
r->item=historyList[i]->line; |
101 |
106 |
|
|
102 |
107 |
hashset_put(&rankmap, line, r); |
hashset_put(&rankmap, line, r); |
|
... |
... |
HistoryItems *get_prioritized_history() |
112 |
117 |
assert(radixItem); |
assert(radixItem); |
113 |
118 |
|
|
114 |
119 |
if(radixItem) { |
if(radixItem) { |
115 |
|
r->rank=HISTORY_RANKING_FUNCTION(r->rank, i, strlen(line)); |
|
|
120 |
|
r->rank=history_ranking_function(r->rank, i, strlen(line)); |
116 |
121 |
radixItem->key=r->rank; |
radixItem->key=r->rank; |
117 |
122 |
radixsort_add(&rs, radixItem); |
radixsort_add(&rs, radixItem); |
118 |
123 |
} |
} |
File src/radixsort.c changed (mode: 100644) (index 7bf6e09..4dfb0b3) |
... |
... |
void radixsort_add(RadixSorter *rs, RadixItem *item) |
45 |
45 |
unsigned topIndex = GET_TOP_INDEX(item->key); |
unsigned topIndex = GET_TOP_INDEX(item->key); |
46 |
46 |
unsigned lowIndex = GET_LOW_INDEX(item->key); |
unsigned lowIndex = GET_LOW_INDEX(item->key); |
47 |
47 |
|
|
48 |
|
|
|
49 |
48 |
if(!rs->topDigits[topIndex]) { |
if(!rs->topDigits[topIndex]) { |
50 |
49 |
rs->topDigits[topIndex]=radixsort_get_slot(rs, topIndex); |
rs->topDigits[topIndex]=radixsort_get_slot(rs, topIndex); |
51 |
50 |
} |
} |