#ifndef NETWORK_SWITCH_UNICAST_TABLE_H
#define NETWORK_SWITCH_UNICAST_TABLE_H

#include <cstdint>
#include <unordered_map>
#include <vector>
#include <algorithm>

#include "core/types.h"

namespace dofs {

class UnicastTable {
public:
        UnicastTable() = default;

        std::vector<PortId> get_port_list(NodeId dst_node, PortId dst_port) const;

        bool add_entry(NodeId dst_node, PortId dst_port, PortId out_port);

        bool delete_entry(NodeId dst_node, PortId dst_port, PortId out_port);

private:
        static constexpr uint32_t kPortShiftBits = 8;

        static bool insert_sorted_unique(std::vector<PortId> &vec, PortId v);

        static bool erase_sorted(std::vector<PortId> &vec, PortId v);

private:
        std::unordered_map<IPv4Addr, std::vector<PortId>> _table;
};

} // namespace dofs

#endif // NETWORK_SWITCH_UNICAST_TABLE_H
