| 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/DataComparator.h"
|
| 12 | #include "souffle/profile/Row.h"
|
| 13 | #include <algorithm>
|
| 14 | #include <memory>
|
| 15 | #include <vector>
|
| 16 |
|
| 17 | namespace souffle {
|
| 18 | namespace profile {
|
| 19 |
|
| 20 | /*
|
| 21 | * Table class for holding a vector of rows
|
| 22 | * And sorting the rows based on a datacomparator function
|
| 23 | */
|
| 24 | class Table {
|
| 25 | public:
|
| 26 | std::vector<std::shared_ptr<Row>> rows;
|
| 27 |
|
| 28 | Table() : rows() {}
|
| 29 |
|
| 30 | void addRow(std::shared_ptr<Row> row) {
|
| 31 | rows.push_back(row);
|
| 32 | }
|
| 33 |
|
| 34 | inline std::vector<std::shared_ptr<Row>> getRows() {
|
| 35 | return rows;
|
| 36 | }
|
| 37 |
|
| 38 | void sort(int col_num) {
|
| 39 | switch (col_num) {
|
| 40 | case 1: std::sort(rows.begin(), rows.end(), DataComparator::NR_T); break;
|
| 41 | case 2: std::sort(rows.begin(), rows.end(), DataComparator::R_T); break;
|
| 42 | case 3: std::sort(rows.begin(), rows.end(), DataComparator::C_T); break;
|
| 43 | case 4: std::sort(rows.begin(), rows.end(), DataComparator::TUP); break;
|
| 44 | case 5: std::sort(rows.begin(), rows.end(), DataComparator::ID); break;
|
| 45 | case 6: std::sort(rows.begin(), rows.end(), DataComparator::NAME); break;
|
| 46 | case 0:
|
| 47 | default: // if the col_num isn't defined use TIME
|
| 48 | std::sort(rows.begin(), rows.end(), DataComparator::TIME);
|
| 49 | break;
|
| 50 | }
|
| 51 | }
|
| 52 | };
|
| 53 |
|
| 54 | } // namespace profile
|
| 55 | } // namespace souffle
|