Skip to content

Commit

Permalink
Remove dependence on boost and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardHinnant committed Aug 4, 2014
1 parent 3da6374 commit 85d90f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
6 changes: 2 additions & 4 deletions Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include <map>
#include <cassert>

#include <boost/foreach.hpp>

class NodeState
{
// A NodeState as propagated by the network
Expand Down Expand Up @@ -112,14 +110,14 @@ class Node

bool isOnUNL(int j)
{
BOOST_FOREACH (int v, unl)
for (int v : unl)
if (v==j) return true;
return false;
}

bool hasLinkTo(int j)
{
BOOST_FOREACH (const Link& l, links)
for (const Link& l : links)
if (l.to_node==j) return true;
return false;
}
Expand Down
25 changes: 12 additions & 13 deletions Sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
*/
//==============================================================================

#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <random>

#include "Core.h"

Expand Down Expand Up @@ -62,7 +61,7 @@ void Node::receiveMessage(const Message& m, Network& network)
++messages_received;

// If we were going to send any of this data to that node, skip it
BOOST_FOREACH(Link& link, links)
for (Link& link : links)
{
if ((link.to_node == m.from_node) && (link.lm_send_time >= network.master_time))
{
Expand Down Expand Up @@ -92,7 +91,7 @@ void Node::receiveMessage(const Message& m, Network& network)

// 2) Choose our position change, if any
int unl_count = 0, unl_balance = 0;
BOOST_FOREACH(int node, unl)
for (int node : unl)
{
if (knowledge[node] == 1)
{
Expand Down Expand Up @@ -137,7 +136,7 @@ void Node::receiveMessage(const Message& m, Network& network)
}

// 3) Broadcast the message
BOOST_FOREACH(Link& link, links)
for (Link& link : links)
{
if (pos_change || (link.to_node != m.from_node))
{
Expand Down Expand Up @@ -166,11 +165,11 @@ int main(void)
{

// This will produce the same results each time
boost::random::mt19937 gen;
boost::random::uniform_int_distribution<> r_e2c(MIN_E2C_LATENCY, MAX_E2C_LATENCY);
boost::random::uniform_int_distribution<> r_c2c(MIN_C2C_LATENCY, MAX_C2C_LATENCY);
boost::random::uniform_int_distribution<> r_unl(UNL_MIN, UNL_MAX);
boost::random::uniform_int_distribution<> r_node(0, NUM_NODES-1);
std::mt19937 gen;
std::uniform_int_distribution<> r_e2c(MIN_E2C_LATENCY, MAX_E2C_LATENCY);
std::uniform_int_distribution<> r_c2c(MIN_C2C_LATENCY, MAX_C2C_LATENCY);
std::uniform_int_distribution<> r_unl(UNL_MIN, UNL_MAX);
std::uniform_int_distribution<> r_node(0, NUM_NODES-1);

Node* nodes[NUM_NODES];

Expand Down Expand Up @@ -233,7 +232,7 @@ int main(void)
std::cerr << "Creating initial messages" << std::endl;
for (int i = 0; i < NUM_NODES; ++i)
{
BOOST_FOREACH(Link& l, nodes[i]->links)
for (Link& l : nodes[i]->links)
{
Message m(i, l.to_node);
m.data.insert(std::make_pair(i, NodeState(i, 1, nodes[i]->knowledge[i])));
Expand Down Expand Up @@ -262,7 +261,7 @@ int main(void)
nodes_positive << "/" << nodes_negative << std::endl;
network.master_time = ev->first;

BOOST_FOREACH(const Message& m, ev->second.messages)
for (const Message& m : ev->second.messages)
{
if (m.data.empty()) // message was never sent
--nodes[m.from_node]->messages_sent;
Expand Down
6 changes: 1 addition & 5 deletions Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
*/
//==============================================================================

#include <iostream>

#include <boost/foreach.hpp>

#include "Core.h"

void Message::addPositions(const std::map<int, NodeState>& update)
Expand All @@ -34,7 +30,7 @@ void Message::addPositions(const std::map<int, NodeState>& update)
// don't tell a node about itself
std::map<int, NodeState>::iterator message_iterator=data.find(update_iterator->first);

if(message_iterator->first)
if(message_iterator != data.end() && message_iterator->first)
{
// we already had data about this node going in this message
if (update_iterator->second.ts > message_iterator->second.ts)
Expand Down

0 comments on commit 85d90f0

Please sign in to comment.