| [2112b1] | 1 | /**
|
|---|
| 2 | * @file key.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Nov 21 13:27:22 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Class to distinguish the different entities in maps.
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #include "comm/mpi/key.hpp"
|
|---|
| 15 | #include "grid/grid.hpp"
|
|---|
| 16 |
|
|---|
| 17 | using namespace VMG;
|
|---|
| 18 |
|
|---|
| 19 | VMG::MPI::Key::Key()
|
|---|
| 20 | {
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| [97c25dd] | 23 | VMG::MPI::Key::Key(const VMG::MPI::Key& other)
|
|---|
| 24 | {
|
|---|
| 25 | this->int_keys.assign(other.int_keys.begin(), other.int_keys.end());
|
|---|
| 26 | this->addr_keys.assign(other.addr_keys.begin(), other.addr_keys.end());
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| [2112b1] | 29 | VMG::MPI::Key::Key(const Grid& grid)
|
|---|
| 30 | {
|
|---|
| 31 | AddKey(grid);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | VMG::MPI::Key::Key(const Grid& grid_1, const Grid& grid_2)
|
|---|
| 35 | {
|
|---|
| 36 | AddKey(grid_1);
|
|---|
| 37 | AddKey(grid_2);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | VMG::MPI::Key::Key(const Index& i1, const Index& i2, const Index& i3)
|
|---|
| 41 | {
|
|---|
| 42 | AddKey(i1);
|
|---|
| 43 | AddKey(i2);
|
|---|
| 44 | AddKey(i3);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void VMG::MPI::Key::AddKey(const Grid& grid)
|
|---|
| 48 | {
|
|---|
| 49 | for (int i=0; i<3; ++i) {
|
|---|
| 50 | int_keys.push_back(grid.Global().BeginLocal()[i]);
|
|---|
| 51 | int_keys.push_back(grid.Global().EndLocal()[i]);
|
|---|
| 52 | int_keys.push_back(grid.Global().SizeGlobal()[i]);
|
|---|
| 53 | }
|
|---|
| 54 | addr_keys.push_back(reinterpret_cast<const void*>(&grid));
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | void VMG::MPI::Key::AddKey(const Index& index)
|
|---|
| 58 | {
|
|---|
| 59 | for (int i=0; i<3; ++i)
|
|---|
| 60 | int_keys.push_back(index[i]);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void VMG::MPI::Key::AddKey(const int& i)
|
|---|
| 64 | {
|
|---|
| 65 | int_keys.push_back(i);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void VMG::MPI::Key::AddKey(const void* addr)
|
|---|
| 69 | {
|
|---|
| 70 | addr_keys.push_back(addr);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | bool VMG::MPI::Key::operator<(const Key& other) const
|
|---|
| 74 | {
|
|---|
| 75 | if (this->int_keys.size() < other.int_keys.size())
|
|---|
| 76 | return true;
|
|---|
| 77 | else if (this->int_keys.size() > other.int_keys.size())
|
|---|
| 78 | return false;
|
|---|
| 79 |
|
|---|
| 80 | if (this->addr_keys.size() < other.addr_keys.size())
|
|---|
| 81 | return true;
|
|---|
| 82 | else if (this->addr_keys.size() > other.addr_keys.size())
|
|---|
| 83 | return false;
|
|---|
| 84 |
|
|---|
| 85 | for (unsigned int i=0; i<int_keys.size(); ++i)
|
|---|
| 86 | if (this->int_keys[i] < other.int_keys[i])
|
|---|
| 87 | return true;
|
|---|
| 88 | else if (this->int_keys[i] > other.int_keys[i])
|
|---|
| 89 | return false;
|
|---|
| 90 |
|
|---|
| 91 | for (unsigned int i=0; i<addr_keys.size(); ++i)
|
|---|
| 92 | if (this->addr_keys[i] < other.addr_keys[i])
|
|---|
| 93 | return true;
|
|---|
| [97c25dd] | 94 | else if (this-> addr_keys[i] > other.addr_keys[i])
|
|---|
| [2112b1] | 95 | return false;
|
|---|
| 96 |
|
|---|
| 97 | return false;
|
|---|
| 98 | }
|
|---|