OILS / vendor / souffle / profile / DataComparator.h View on Github | oilshell.org

66 lines, 25 significant
1/*
2 * Souffle - A Datalog Compiler
3 * Copyright (c) 2016, The Souffle Developers. All rights reserved
4 * Licensed under the Universal Permissive License v 1.0 as shown at:
5 * - https://opensource.org/licenses/UPL
6 * - <souffle root>/licenses/SOUFFLE-UPL.txt
7 */
8
9#pragma once
10
11#include "souffle/profile/CellInterface.h"
12#include "souffle/profile/Row.h"
13
14#include <cmath>
15#include <memory>
16#include <vector>
17
18namespace souffle {
19namespace profile {
20
21/*
22 * Data comparison functions for sorting tables
23 *
24 * Will sort the values of only one column, in descending order
25 *
26 */
27class DataComparator {
28public:
29 /** Sort by total time. */
30 static bool TIME(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
31 return a->cells[0]->getDoubleVal() > b->cells[0]->getDoubleVal();
32 }
33
34 /** Sort by non-recursive time. */
35 static bool NR_T(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
36 return a->cells[1]->getDoubleVal() > b->cells[1]->getDoubleVal();
37 }
38
39 /** Sort by recursive time. */
40 static bool R_T(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
41 return a->cells[2]->getDoubleVal() > b->cells[2]->getDoubleVal();
42 }
43
44 /** Sort by copy time. */
45 static bool C_T(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
46 return a->cells[3]->getDoubleVal() > b->cells[3]->getDoubleVal();
47 }
48
49 /** Sort by tuple count. */
50 static bool TUP(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
51 return b->cells[4]->getLongVal() < a->cells[4]->getLongVal();
52 }
53
54 /** Sort by name. */
55 static bool NAME(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
56 return b->cells[5]->getStringVal() > a->cells[5]->getStringVal();
57 }
58
59 /** Sort by ID. */
60 static bool ID(const std::shared_ptr<Row>& a, const std::shared_ptr<Row>& b) {
61 return b->cells[6]->getStringVal() > a->cells[6]->getStringVal();
62 }
63};
64
65} // namespace profile
66} // namespace souffle