Skip to content
Open
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
17 changes: 17 additions & 0 deletions common/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,23 @@ enum class eNexthopType : unsigned int
repeat,
};

inline std::string InterfaceName(eNexthopType nh)
{
switch (nh)
{
case eNexthopType::controlPlane:
return "linux";
case eNexthopType::repeat:
return "repeat";
default:
#if __cpp_exceptions
throw std::invalid_argument{"No valid conversion from eNexthopType to interface name string"};
#else
std::exit(EXIT_FAILURE);
#endif
}
}

enum class eFlowType : uint8_t
{
drop,
Expand Down
10 changes: 10 additions & 0 deletions common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,15 @@ class Job
}
};

// helper type for the variant visitor
template<class... Ts>
struct Visitor : Ts...
{
using Ts::operator()...;
};
// explicit deduction guide (not needed as of C++20)
template<class... Ts>
Visitor(Ts...) -> Visitor<Ts...>;

}
// namespace utils
30 changes: 19 additions & 11 deletions common/weight.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ class weight_t
}

public:
std::tuple<uint32_t, uint32_t, bool> insert(const std::vector<uint32_t>& weights)
struct Range
{
uint32_t start;
uint32_t size;
};

struct InsertResult
{
Range range;
bool is_fallback;
};

InsertResult insert(const std::vector<uint32_t>& weights)
{
/// @todo: check weights.size()

Expand All @@ -38,11 +50,7 @@ class weight_t
}
else
{
uint32_t weight_total = 0;
for (const auto& weight : weights)
{
weight_total += weight;
}
uint32_t weight_total = std::accumulate(weights.begin(), weights.end(), uint32_t{});
if (size + weight_total > size_T)
{
YANET_LOG_WARNING("not enough weights\n");
Expand All @@ -55,9 +63,9 @@ class weight_t
return {0, std::min((uint32_t)weights.size(), (uint32_t)256), true}; ///< fallback
}

auto& [range_start, range_size] = ranges[*id];
Range& range = ranges[*id];

range_start = size;
range.start = size;

index_type_T item_i = 0;
for (const auto& weight : weights)
Expand All @@ -68,10 +76,10 @@ class weight_t
size += weight;
}

range_size = size - range_start;
range.size = size - range.start;
}

return std::tuple_cat(ranges[values.get_id(weights)], std::make_tuple(false));
return {ranges[values.get_id(weights)], false};
}

void clear()
Expand Down Expand Up @@ -108,7 +116,7 @@ class weight_t
values;

std::map<uint64_t, ///< refarray_t::id_t
std::tuple<uint32_t, uint32_t>>
Range>
ranges;

mutable std::vector<index_type_T> base;
Expand Down
Loading