Mark List::sort as deprecated, remove List::sortedinsert

This commit is contained in:
Tim Wojtulewicz 2019-07-17 14:36:11 -07:00 committed by Jon Siwek
parent e860a4b22d
commit d2d5043bf0
3 changed files with 13 additions and 36 deletions

View file

@ -27,6 +27,7 @@
#include <cassert>
#include "util.h"
// TODO: this can be removed in v3.1 when List::sort() is removed
typedef int (*list_cmp_func)(const void* v1, const void* v2);
template<typename T>
@ -154,6 +155,7 @@ public:
return max_entries;
}
ZEEK_DEPRECATED("Remove in v3.1: Use std::sort instead")
void sort(list_cmp_func cmp_func)
{
qsort(entries, num_entries, sizeof(T), cmp_func);
@ -174,31 +176,6 @@ public:
entries[0] = a;
}
// Assumes that the list is sorted and inserts at correct position.
void sortedinsert(const T& a, list_cmp_func cmp_func)
{
// We optimize for the case that the new element is
// larger than most of the current entries.
// First append element.
if ( num_entries == max_entries )
resize(max_entries ? max_entries * LIST_GROWTH_FACTOR : DEFAULT_LIST_SIZE);
entries[num_entries++] = a;
// Then move it to the correct place.
T tmp;
for ( int i = num_entries - 1; i > 0; --i )
{
if ( cmp_func(entries[i],entries[i-1]) <= 0 )
break;
tmp = entries[i];
entries[i] = entries[i-1];
entries[i-1] = tmp;
}
}
void push_back(const T& a) { append(a); }
void push_front(const T& a) { insert(a); }
void pop_front() { remove_nth(0); }

View file

@ -2,6 +2,8 @@
#include "zeek-config.h"
#include <algorithm>
#include "NFA.h"
#include "EquivClass.h"
@ -342,11 +344,14 @@ NFA_state_list* epsilon_closure(NFA_state_list* states)
if ( ! closuremap.Contains(ns->ID()) )
{
closuremap.Insert(ns->ID());
closure->sortedinsert(ns, NFA_state_cmp_neg);
closure->append(ns);
}
}
}
// Sort all of the closures in the list by ID
std::sort(closure->begin(), closure->end(), NFA_state_cmp_neg);
// Make it fit.
closure->resize(0);
@ -355,15 +360,10 @@ NFA_state_list* epsilon_closure(NFA_state_list* states)
return closure;
}
int NFA_state_cmp_neg(const void* v1, const void* v2)
bool NFA_state_cmp_neg(const NFA_State* v1, const NFA_State* v2)
{
const NFA_State* n1 = (const NFA_State*) v1;
const NFA_State* n2 = (const NFA_State*) v2;
if ( n1->ID() < n2->ID() )
return -1;
else if ( n1->ID() == n2->ID() )
return 0;
if ( v1->ID() < v2->ID() )
return true;
else
return 1;
return false;
}

View file

@ -132,6 +132,6 @@ extern NFA_Machine* make_alternate(NFA_Machine* m1, NFA_Machine* m2);
extern NFA_state_list* epsilon_closure(NFA_state_list* states);
// For sorting NFA states based on their ID fields (decreasing)
extern int NFA_state_cmp_neg(const void* v1, const void* v2);
extern bool NFA_state_cmp_neg(const NFA_State* v1, const NFA_State* v2);
#endif