Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
615 changes: 584 additions & 31 deletions examples/treeTest.cpp

Large diffs are not rendered by default.

612 changes: 306 additions & 306 deletions include/manetGraph.h

Large diffs are not rendered by default.

390 changes: 195 additions & 195 deletions include/protoGraph.h

Large diffs are not rendered by default.

177 changes: 91 additions & 86 deletions include/protoList.h

Large diffs are not rendered by default.

421 changes: 229 additions & 192 deletions include/protoTree.h

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/bsd/bsdNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void TryGetEndpointsBySysctlRoute(const char* ifname,
if (0 != sysctl(mib, 6, nullptr, &needed, nullptr, 0) || needed == 0)
return;

char* buf = (char*)std::malloc(needed);
void* buf = (char*)std::malloc(needed);
if (!buf) return;

if (0 != sysctl(mib, 6, buf, &needed, nullptr, 0))
Expand All @@ -206,17 +206,17 @@ static void TryGetEndpointsBySysctlRoute(const char* ifname,
return;
}

char* end = buf + needed;
void* end = ((char*)buf) + needed;

for (char* p = buf; p < end; )
for (void* p = buf; p < end; )
{
struct if_msghdr* ifm = (struct if_msghdr*)p;
if (ifm->ifm_msglen == 0) break;

if (ifm->ifm_type == RTM_IFINFO)
{
// Followed by sockaddr_dl containing name
char* cp = p + sizeof(struct if_msghdr);
void* cp = ((char*)p) + sizeof(struct if_msghdr);
struct sockaddr_dl* sdl = (struct sockaddr_dl*)cp;

if (sdl->sdl_family == AF_LINK)
Expand All @@ -232,7 +232,7 @@ static void TryGetEndpointsBySysctlRoute(const char* ifname,
bool gotLocal = false;
bool gotRemote = false;

char* q = p + ifm->ifm_msglen;
void* q = ((char*)p) + ifm->ifm_msglen;
while (q < end)
{
struct if_msghdr* mh = (struct if_msghdr*)q;
Expand All @@ -242,7 +242,7 @@ static void TryGetEndpointsBySysctlRoute(const char* ifname,
if (mh->ifm_type == RTM_NEWADDR)
{
struct ifa_msghdr* ifam = (struct ifa_msghdr*)q;
char* sa_ptr = q + sizeof(struct ifa_msghdr);
void* sa_ptr = ((char*)q) + sizeof(struct ifa_msghdr);

const struct sockaddr* rta[RTAX_MAX];
std::memset(rta, 0, sizeof(rta));
Expand All @@ -253,7 +253,7 @@ static void TryGetEndpointsBySysctlRoute(const char* ifname,
{
const struct sockaddr* sa = (const struct sockaddr*)sa_ptr;
rta[i] = sa;
sa_ptr += sa_rounded_len(sa);
sa_ptr = ((char*)sa_ptr) + sa_rounded_len(sa);
}
}

Expand All @@ -278,13 +278,13 @@ static void TryGetEndpointsBySysctlRoute(const char* ifname,
}
}

q += mh->ifm_msglen;
q = ((char*)q) + mh->ifm_msglen;
}
}
}
}

p += ifm->ifm_msglen;
p = ((char*)p) + ifm->ifm_msglen;
}

std::free(buf);
Expand Down
2 changes: 1 addition & 1 deletion src/common/protoGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ ProtoGraph::AdjacencyQueue::~AdjacencyQueue()
void ProtoGraph::AdjacencyQueue::Empty()
{
Edge* edge;
while (NULL != (edge = static_cast<Edge*>(adjacency_tree.GetRoot())))
while (NULL != (edge = static_cast<Edge*>(adjacency_tree.GetHead())))
{
Vertice* dst = edge->GetDst();
ASSERT(NULL != dst);
Expand Down
61 changes: 30 additions & 31 deletions src/common/protoSpace.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file protoSpace.cpp
*
*
* @brief This maintains a set of "Nodes" in n-dimensional Euclidean space.
*/
// Uncomment this to have SDT display bounding box iteration
Expand All @@ -9,7 +9,7 @@
#include "protoDebug.h"

#include "protoSpace.h"
#include <math.h> // for "fabs()"
#include <math.h> // for "fabs()"
#include <stdio.h> // for "printf()"
ProtoSpace::Node::Node()
{
Expand Down Expand Up @@ -96,7 +96,7 @@ bool ProtoSpace::InsertNode(Node& node)
PLOG(PL_ERROR, "ProtoSpace::InsertNode() error: Node dimensions does not match space!\n");
return false;
}

// Get and Insert "Ordinate" entries for the node for each dimension
for (unsigned int i = 0; i < num_dimensions; i++)
{
Expand Down Expand Up @@ -190,7 +190,7 @@ bool ProtoSpace::Iterator::Init(const double* originOrdinates)
memcpy(orig, originOrdinates, dim*sizeof(double));
else
memset(orig, 0, dim*sizeof(double));

// Allocate and init positive ordinate iterators
if (NULL == (pos_it = new ProtoSortedTree::Iterator*[dim]))
{
Expand All @@ -204,16 +204,16 @@ bool ProtoSpace::Iterator::Init(const double* originOrdinates)
for (unsigned int i = 0; i < dim; i++)
{
tempOrd.SetValue(orig[i]);
if (NULL == (pos_it[i] = new ProtoSortedTree::Iterator(space.ord_tree[i],
false,
if (NULL == (pos_it[i] = new ProtoSortedTree::Iterator(space.ord_tree[i],
false,
tempOrd.GetKey(),
Ordinate::KEYBITS)))
{
Destroy();
return false;
}
}

// Allocate and init negative ordinate iterators
if (NULL == (neg_it = new ProtoSortedTree::Iterator*[dim]))
{
Expand All @@ -226,8 +226,8 @@ bool ProtoSpace::Iterator::Init(const double* originOrdinates)
for (unsigned int i = 0; i < dim; i++)
{
tempOrd.SetValue(orig[i]);
if (NULL == (neg_it[i] = new ProtoSortedTree::Iterator(space.ord_tree[i],
false,
if (NULL == (neg_it[i] = new ProtoSortedTree::Iterator(space.ord_tree[i],
false,
tempOrd.GetKey(),
Ordinate::KEYBITS)))
{
Expand All @@ -248,10 +248,10 @@ bool ProtoSpace::Iterator::Init(const double* originOrdinates)
printf("link ur,lr,blue,2\n");
printf("link ll,lr,blue,2\n");
#endif // USE_SDT

bbox_radius = 0.0;
x_factor = sqrt((double)dim);

return true;
} // end ProtoSpace::Iterator::Init()

Expand Down Expand Up @@ -298,9 +298,9 @@ void ProtoSpace::Iterator::Reset(const double* originOrdinates)
for (unsigned int i = 0; i < dim; i++)
{
tempOrd.SetValue(orig[i]);
pos_it[i]->Reset(false, tempOrd.GetKey(), Ordinate::KEYBITS);
neg_it[i]->Reset(false, tempOrd.GetKey(), Ordinate::KEYBITS);
neg_it[i]->Reverse();
pos_it[i]->Reset(false, tempOrd.GetKey(), Ordinate::KEYBITS);
neg_it[i]->Reset(false, tempOrd.GetKey(), Ordinate::KEYBITS);
neg_it[i]->Reverse();
}
// empty our queue
Ordinate* nextOrd;
Expand All @@ -313,7 +313,7 @@ void ProtoSpace::Iterator::Reset(const double* originOrdinates)
* bounding box that meets these criteria
* 1) Closest location to <orig_x, orig_y>, _and_
* 2) Falls within the current bounding box
*/
*/
ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
{
unsigned int dim = space.GetDimensions();
Expand All @@ -327,7 +327,7 @@ ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
bool inBox = true;
if (bbox_radius >= 0.0)
{

// Is the "nextNode" within the bbox*x_factor
// (Note "x_factor = radius * sqrt(num_dimensions))
double xRadius = bbox_radius / x_factor;
Expand All @@ -344,21 +344,21 @@ ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
if (inBox)
{
ord_tree.RemoveHead();
if (NULL != distance)
if (NULL != distance)
{
*distance = sqrt(nextOrd->GetValue());
}
space.ReturnOrdinateToPool(*nextOrd);
return nextNode;
}

}
else if (bbox_radius < 0.0)
{
return NULL; // finished
}


// A) Find the ordinate with smallest delta from origin
// to set "radius" of current bounding space
double deltaMin = -1.0;
Expand Down Expand Up @@ -386,16 +386,16 @@ ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
}
}
bbox_radius = deltaMin;
if (deltaMin < 0.0) continue;
if (deltaMin < 0.0) continue;

// Output new bounding box for SDT visualization
#ifdef USE_SDT
printf("node ul position %f,%f\n", orig[0] - deltaMin, orig[1] - deltaMin);
printf("node ur position %f,%f\n", orig[0] + deltaMin, orig[1] - deltaMin);
printf("node ll position %f,%f\n", orig[0] - deltaMin, orig[1] + deltaMin);
printf("node lr position %f,%f\n", orig[0] + deltaMin, orig[1] + deltaMin);
#endif // USE_SDT

Node* node = neg ? static_cast<Ordinate*>(neg_it[index]->PeekPrevItem())->GetNode() :
static_cast<Ordinate*>(pos_it[index]->PeekNextItem())->GetNode();

Expand All @@ -410,7 +410,7 @@ ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
break;
}
}

// C) Enqueue any nodes that lie _within_ the current bounding space
if (inBox)
{
Expand All @@ -421,8 +421,8 @@ ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
double delta = node->GetOrdinate(j) - orig[j];
distPartial += delta*delta;
}
// b) get and init Ordinate

// b) get and init Ordinate
Ordinate* ord = space.GetOrdinateFromPool();
if ((NULL == ord) && (NULL == (ord = new Ordinate)))
{
Expand All @@ -432,26 +432,25 @@ ProtoSpace::Node* ProtoSpace::Iterator::GetNextNode(double* distance)
}
ord->SetNode(node);
ord->SetValue(distPartial);

// c) if not already enqueued, enqueue it
if (NULL == ord_tree.Find(ord->GetKey(), Ordinate::KEYBITS))
ord_tree.Insert(*ord);
else
space.ReturnOrdinateToPool(*ord);
}

// D) Consume the applicable ordinate, expanding our bounding box
if (neg)
neg_it[index]->GetPrevItem();
else
pos_it[index]->GetNextItem();

#ifdef USE_SDT
#ifdef USE_SDT
printf("wait 1\n");
#endif // USE_SDT

} // end while(1)

} // end ProtoSpace::Iterator::GetNextNode()


Loading
Loading