Vowpal Wabbit
Classes | Functions
Beam Namespace Reference

Classes

class  beam
 
struct  beam_element
 

Functions

int compare_on_cost (const void *void_a, const void *void_b)
 
int compare_on_hash_then_cost (const void *void_a, const void *void_b)
 

Function Documentation

◆ compare_on_cost()

int Beam::compare_on_cost ( const void *  void_a,
const void *  void_b 
)
inline

Definition at line 32 of file beam.h.

References a, Beam::beam_element< T >::active, and Beam::beam_element< T >::cost.

Referenced by Beam::beam< T >::compact().

33 {
34  if (void_a == void_b)
35  return 0;
36  const beam_element<void> *a = (const beam_element<void> *)void_a;
37  const beam_element<void> *b = (const beam_element<void> *)void_b;
38  if (a->active && !b->active)
39  return -1; // active things come before inactive things
40  else if (!a->active && b->active)
41  return 1;
42  else if (!a->active && !b->active)
43  return 0;
44  else if (a->cost < b->cost)
45  return -1; // otherwise sort by cost
46  else if (a->cost > b->cost)
47  return 1;
48  else
49  return 0;
50 }
constexpr uint64_t a
Definition: rand48.cc:11

◆ compare_on_hash_then_cost()

int Beam::compare_on_hash_then_cost ( const void *  void_a,
const void *  void_b 
)
inline

Definition at line 52 of file beam.h.

References a, Beam::beam_element< T >::active, Beam::beam_element< T >::cost, and Beam::beam_element< T >::hash.

Referenced by Beam::beam< T >::do_recombination().

53 {
54  if (void_a == void_b)
55  return 0;
56  const beam_element<void> *a = (const beam_element<void> *)void_a;
57  const beam_element<void> *b = (const beam_element<void> *)void_b;
58  if (a->active && !b->active)
59  return -1; // active things come before inactive things
60  else if (!a->active && b->active)
61  return 1;
62  else if (!a->active && !b->active)
63  return 0;
64  else if (a->hash < b->hash)
65  return -1; // if the hashes are different, sort by hash
66  else if (a->hash > b->hash)
67  return 1;
68  else if (a->cost < b->cost)
69  return -1; // otherwise sort by cost
70  else if (a->cost > b->cost)
71  return 1;
72  else
73  return 0;
74 }
constexpr uint64_t a
Definition: rand48.cc:11