summaryrefslogtreecommitdiff
path: root/graphs/cpp/closer_to/closer_to.cc
blob: 779d3b5fd58c66a881e2c18f62f5b79d7f29d42c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// Created by martial.simon on 2/25/25.
//
#include "closer_to.hh"
CloserTo::CloserTo(int i)
    : i_{ i }
{}
bool CloserTo::operator()(int a, int b) const
{
    const int da = a - i_ >= 0 ? a - i_ : i_ - a;
    const int db = b - i_ >= 0 ? b - i_ : i_ - b;
    if (da == db)
        return a < b;
    return da < db;
}