mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The one place where we deviate is header include order since Zeek depends on headers being included in a certain order.
This commit is contained in:
parent
7b8e7ed72c
commit
f5a76c1aed
786 changed files with 131714 additions and 153609 deletions
|
@ -10,133 +10,116 @@
|
|||
#include "zeek/Reporter.h"
|
||||
#include "zeek/util.h"
|
||||
|
||||
namespace zeek::detail
|
||||
{
|
||||
namespace zeek::detail {
|
||||
|
||||
PriorityQueue::PriorityQueue(int initial_size) : max_heap_size(initial_size)
|
||||
{
|
||||
heap = new PQ_Element*[max_heap_size];
|
||||
}
|
||||
PriorityQueue::PriorityQueue(int initial_size) : max_heap_size(initial_size) { heap = new PQ_Element*[max_heap_size]; }
|
||||
|
||||
PriorityQueue::~PriorityQueue()
|
||||
{
|
||||
for ( int i = 0; i < heap_size; ++i )
|
||||
delete heap[i];
|
||||
PriorityQueue::~PriorityQueue() {
|
||||
for ( int i = 0; i < heap_size; ++i )
|
||||
delete heap[i];
|
||||
|
||||
delete[] heap;
|
||||
}
|
||||
delete[] heap;
|
||||
}
|
||||
|
||||
PQ_Element* PriorityQueue::Remove()
|
||||
{
|
||||
if ( heap_size == 0 )
|
||||
return nullptr;
|
||||
PQ_Element* PriorityQueue::Remove() {
|
||||
if ( heap_size == 0 )
|
||||
return nullptr;
|
||||
|
||||
PQ_Element* top = heap[0];
|
||||
PQ_Element* top = heap[0];
|
||||
|
||||
--heap_size;
|
||||
SetElement(0, heap[heap_size]);
|
||||
BubbleDown(0);
|
||||
--heap_size;
|
||||
SetElement(0, heap[heap_size]);
|
||||
BubbleDown(0);
|
||||
|
||||
top->SetOffset(-1); // = not in heap
|
||||
return top;
|
||||
}
|
||||
top->SetOffset(-1); // = not in heap
|
||||
return top;
|
||||
}
|
||||
|
||||
PQ_Element* PriorityQueue::Remove(PQ_Element* e)
|
||||
{
|
||||
if ( e->Offset() < 0 || e->Offset() >= heap_size || heap[e->Offset()] != e )
|
||||
return nullptr; // not in heap
|
||||
PQ_Element* PriorityQueue::Remove(PQ_Element* e) {
|
||||
if ( e->Offset() < 0 || e->Offset() >= heap_size || heap[e->Offset()] != e )
|
||||
return nullptr; // not in heap
|
||||
|
||||
e->MinimizeTime();
|
||||
BubbleUp(e->Offset());
|
||||
e->MinimizeTime();
|
||||
BubbleUp(e->Offset());
|
||||
|
||||
PQ_Element* e2 = Remove();
|
||||
PQ_Element* e2 = Remove();
|
||||
|
||||
if ( e != e2 )
|
||||
reporter->InternalError("inconsistency in PriorityQueue::Remove");
|
||||
if ( e != e2 )
|
||||
reporter->InternalError("inconsistency in PriorityQueue::Remove");
|
||||
|
||||
return e2;
|
||||
}
|
||||
return e2;
|
||||
}
|
||||
|
||||
bool PriorityQueue::Add(PQ_Element* e)
|
||||
{
|
||||
SetElement(heap_size, e);
|
||||
bool PriorityQueue::Add(PQ_Element* e) {
|
||||
SetElement(heap_size, e);
|
||||
|
||||
BubbleUp(heap_size);
|
||||
BubbleUp(heap_size);
|
||||
|
||||
++cumulative_num;
|
||||
++cumulative_num;
|
||||
|
||||
if ( ++heap_size > peak_heap_size )
|
||||
peak_heap_size = heap_size;
|
||||
if ( ++heap_size > peak_heap_size )
|
||||
peak_heap_size = heap_size;
|
||||
|
||||
if ( heap_size >= max_heap_size )
|
||||
return Resize(max_heap_size * 2);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
if ( heap_size >= max_heap_size )
|
||||
return Resize(max_heap_size * 2);
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PriorityQueue::Resize(int new_size)
|
||||
{
|
||||
PQ_Element** tmp = new PQ_Element*[new_size];
|
||||
for ( int i = 0; i < max_heap_size; ++i )
|
||||
tmp[i] = heap[i];
|
||||
bool PriorityQueue::Resize(int new_size) {
|
||||
PQ_Element** tmp = new PQ_Element*[new_size];
|
||||
for ( int i = 0; i < max_heap_size; ++i )
|
||||
tmp[i] = heap[i];
|
||||
|
||||
delete[] heap;
|
||||
heap = tmp;
|
||||
delete[] heap;
|
||||
heap = tmp;
|
||||
|
||||
max_heap_size = new_size;
|
||||
max_heap_size = new_size;
|
||||
|
||||
return heap != nullptr;
|
||||
}
|
||||
return heap != nullptr;
|
||||
}
|
||||
|
||||
void PriorityQueue::BubbleUp(int bin)
|
||||
{
|
||||
if ( bin == 0 )
|
||||
return;
|
||||
void PriorityQueue::BubbleUp(int bin) {
|
||||
if ( bin == 0 )
|
||||
return;
|
||||
|
||||
int p = Parent(bin);
|
||||
if ( heap[p]->Time() > heap[bin]->Time() )
|
||||
{
|
||||
Swap(p, bin);
|
||||
BubbleUp(p);
|
||||
}
|
||||
}
|
||||
int p = Parent(bin);
|
||||
if ( heap[p]->Time() > heap[bin]->Time() ) {
|
||||
Swap(p, bin);
|
||||
BubbleUp(p);
|
||||
}
|
||||
}
|
||||
|
||||
void PriorityQueue::BubbleDown(int bin)
|
||||
{
|
||||
double v = heap[bin]->Time();
|
||||
void PriorityQueue::BubbleDown(int bin) {
|
||||
double v = heap[bin]->Time();
|
||||
|
||||
int l = LeftChild(bin);
|
||||
int r = RightChild(bin);
|
||||
int l = LeftChild(bin);
|
||||
int r = RightChild(bin);
|
||||
|
||||
if ( l >= heap_size )
|
||||
return; // No children.
|
||||
if ( l >= heap_size )
|
||||
return; // No children.
|
||||
|
||||
if ( r >= heap_size )
|
||||
{ // Just a left child.
|
||||
if ( heap[l]->Time() < v )
|
||||
Swap(l, bin);
|
||||
}
|
||||
if ( r >= heap_size ) { // Just a left child.
|
||||
if ( heap[l]->Time() < v )
|
||||
Swap(l, bin);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
double lv = heap[l]->Time();
|
||||
double rv = heap[r]->Time();
|
||||
else {
|
||||
double lv = heap[l]->Time();
|
||||
double rv = heap[r]->Time();
|
||||
|
||||
if ( lv < rv )
|
||||
{
|
||||
if ( lv < v )
|
||||
{
|
||||
Swap(l, bin);
|
||||
BubbleDown(l);
|
||||
}
|
||||
}
|
||||
if ( lv < rv ) {
|
||||
if ( lv < v ) {
|
||||
Swap(l, bin);
|
||||
BubbleDown(l);
|
||||
}
|
||||
}
|
||||
|
||||
else if ( rv < v )
|
||||
{
|
||||
Swap(r, bin);
|
||||
BubbleDown(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( rv < v ) {
|
||||
Swap(r, bin);
|
||||
BubbleDown(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace zeek::detail
|
||||
} // namespace zeek::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue