xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit 80c2cba194a080bef6a482c21b918da86eedb507

Added assert to protect radix and set and thus fixed #21.
Author: Martin Dvorak
Author date (UTC): 2014-01-18 23:01
Committer name: Martin Dvorak
Committer date (UTC): 2014-01-18 23:01
Parent(s): 4cb887b0d4d2508271391fc31f2b8c64dc060888
Signing key:
Tree: 643c49f7ba4cef85b10b2b42ddee4046cf7c72de
File Lines added Lines deleted
src/hstr_history.c 8 3
src/radixsort.c 0 1
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 } }
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master