summaryrefslogtreecommitdiff
path: root/ft/comparator.h
blob: 7591c308400ab9d4e69e1a173a4d228777e16c81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * comparator.h
 */

#ifndef COMPARATOR_H
#define COMPARATOR_H

#include <db.h>
#include <string.h>

#include <ft/ybt.h>
#include <ft/fttypes.h>

namespace toku {

// a comparator object encapsulates the data necessary for 
// comparing two keys in a fractal tree. it further understands
// that points may be positive or negative infinity.

class comparator {
public:
    void set_descriptor(DESCRIPTOR desc) {
        m_fake_db.cmp_descriptor = desc;
    }

    void create(ft_compare_func cmp, DESCRIPTOR desc) {
        m_cmp = cmp;
        memset(&m_fake_db, 0, sizeof(m_fake_db));
        m_fake_db.cmp_descriptor = desc;
    }

    int compare(const DBT *a, const DBT *b) {
        if (toku_dbt_is_infinite(a) || toku_dbt_is_infinite(b)) {
            return toku_dbt_infinite_compare(a, b);
        } else {
            return m_cmp(&m_fake_db, a, b);
        }
    }

private:
    struct __toku_db m_fake_db;
    ft_compare_func m_cmp;
};

} /* namespace toku */

#endif /* COMPARATOR_H */