Vowpal Wabbit
Classes | Namespaces | Functions
spanning_tree.cc File Reference
#include "spanning_tree.h"
#include "vw_exception.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <cmath>
#include <map>
#include <future>

Go to the source code of this file.

Classes

struct  client
 
struct  partial
 

Namespaces

 VW
 

Functions

static int socket_sort (const void *s1, const void *s2)
 
int build_tree (int *parent, uint16_t *kid_count, size_t source_count, int offset)
 
void fail_send (const socket_t fd, const void *buf, const int count)
 

Function Documentation

◆ build_tree()

int build_tree ( int *  parent,
uint16_t *  kid_count,
size_t  source_count,
int  offset 
)

Definition at line 43 of file spanning_tree.cc.

Referenced by VW::SpanningTree::Run().

44 {
45  if (source_count == 1)
46  {
47  kid_count[offset] = 0;
48  return offset;
49  }
50 
51  int height = (int)floor(log((double)source_count) / log(2.0));
52  int root = (1 << height) - 1;
53  int left_count = root;
54  int left_offset = offset;
55  int left_child = build_tree(parent, kid_count, left_count, left_offset);
56  int oroot = root + offset;
57  parent[left_child] = oroot;
58 
59  size_t right_count = source_count - left_count - 1;
60  if (right_count > 0)
61  {
62  int right_offset = oroot + 1;
63 
64  int right_child = build_tree(parent, kid_count, right_count, right_offset);
65  parent[right_child] = oroot;
66  kid_count[oroot] = 2;
67  }
68  else
69  kid_count[oroot] = 1;
70 
71  return oroot;
72 }
int build_tree(int *parent, uint16_t *kid_count, size_t source_count, int offset)

◆ fail_send()

void fail_send ( const socket_t  fd,
const void *  buf,
const int  count 
)

Definition at line 74 of file spanning_tree.cc.

References THROWERRNO.

Referenced by VW::SpanningTree::Run().

75 {
76  if (send(fd, (char*)buf, count, 0) == -1)
77  THROWERRNO("send: ");
78 }
#define THROWERRNO(args)
Definition: vw_exception.h:167

◆ socket_sort()

static int socket_sort ( const void *  s1,
const void *  s2 
)
static

Definition at line 33 of file spanning_tree.cc.

References client::client_ip, and client::socket.

Referenced by VW::SpanningTree::Run().

34 {
35  client* socket1 = (client*)s1;
36  client* socket2 = (client*)s2;
37  if (socket1->client_ip != socket2->client_ip)
38  return socket1->client_ip - socket2->client_ip;
39  else
40  return (int)(socket1->socket - socket2->socket);
41 }
socket_t socket
uint32_t client_ip