Skip to content

Commit

Permalink
Merge pull request #9 from faodel/kelpie/refactor-object-capacities
Browse files Browse the repository at this point in the history
KELPIE: Update ObjectCapacities
  • Loading branch information
tkordenbrock committed Jan 25, 2021
2 parents 7f1c96f + 12fdf8e commit 7dc8d2d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.8.0)
project( Faodel
LANGUAGES CXX C
VERSION 1.1906.1
VERSION 1.1906.2
)


Expand Down
4 changes: 3 additions & 1 deletion src/kelpie/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set( HEADERS_PUBLIC
Kelpie.hh
Key.hh
common/KelpieInternal.hh
common/ObjectCapacities.hh
common/Types.hh
ioms/IomBase.hh
ioms/IomRegistry.hh
Expand Down Expand Up @@ -42,6 +43,7 @@ set( SOURCES
Kelpie.cpp
Key.cpp
common/KelpieInternal.cpp
common/ObjectCapacities.cpp
common/OpArgsObjectAvailable.cpp
common/Types.cpp
core/KelpieCoreBase.cpp
Expand Down Expand Up @@ -126,7 +128,7 @@ install(TARGETS kelpie

install( FILES Kelpie.hh Key.hh
DESTINATION ${INCLUDE_INSTALL_DIR}/faodel/kelpie )
install( FILES common/Types.hh common/KelpieInternal.hh
install( FILES common/Types.hh common/KelpieInternal.hh common/ObjectCapacities.hh
DESTINATION ${INCLUDE_INSTALL_DIR}/faodel/kelpie/common )
install( FILES ioms/IomBase.hh ioms/IomRegistry.hh
DESTINATION ${INCLUDE_INSTALL_DIR}/faodel/kelpie/ioms )
Expand Down
57 changes: 57 additions & 0 deletions src/kelpie/common/ObjectCapacities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2021 National Technology & Engineering Solutions of Sandia,
// LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.

#include "kelpie/common/Types.hh"

using namespace std;

namespace kelpie {

/// Append a key/capacity to this ObjectCapacities. Does NOT dedupe
void ObjectCapacities::Append(const kelpie::Key &key, size_t capacity) {
keys.emplace_back(key);
capacities.emplace_back(capacity);
}

/// Append one ObjectCapacities to another. Does NOT dedupe
void ObjectCapacities::Append(const ObjectCapacities &other) {
keys.insert(keys.end(), other.keys.begin(), other.keys.end());
capacities.insert(capacities.end(), other.capacities.begin(), other.capacities.end());
}

/// Merge two ObjectCapacities. If key exists, do not append from other
void ObjectCapacities::Merge(const ObjectCapacities &other) {
for(int i = 0; i<other.keys.size(); i++) {
auto it = std::find(keys.begin(), keys.end(), other.keys[i]);
if(it == keys.end()) {
Append(other.keys[i], other.capacities[i]);
}
}
}

/// Locate a particular key
int ObjectCapacities::FindIndex(const kelpie::Key &key) {
for(int i = 0; i<keys.size(); i++)
if(keys[i] == key) return i;
return -1;
}



/// Clear out all entries
void ObjectCapacities::Wipe() {
keys.clear();
capacities.clear();
}

void ObjectCapacities::sstr(std::stringstream &ss, int depth, int indent) const {
ss<<string(indent,' ') << "ObjectCapacities Num: "<<keys.size()<<endl;
if(depth>=0) {
for(int i=0; i<keys.size();i++){
ss<<string(indent+2,' ')<<"["<<i<<"] "<<keys[i].str() << "\t" << capacities[i]<<endl;
}
}
}

} // namespace kelpie
49 changes: 49 additions & 0 deletions src/kelpie/common/ObjectCapacities.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2021 National Technology & Engineering Solutions of Sandia,
// LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.

#ifndef FAODEL_OBJECTCAPACITIES_HH
#define FAODEL_OBJECTCAPACITIES_HH

#include <vector>

#include "faodel-common/InfoInterface.hh"

namespace kelpie {

class Key; //Forward reference

class ObjectCapacities :
public faodel::InfoInterface {
public:

//Note: These data structures are plain vectors because some callers need to update capacities first, then set the keys
std::vector <kelpie::Key> keys;
std::vector <size_t> capacities;

/// Append a ket/capacity to this ObjectCapacities. Does NOT dedupe
void Append(const kelpie::Key &key, size_t capacity);
void Append(const ObjectCapacities &other);

void Merge(const ObjectCapacities &other);

int FindIndex(const kelpie::Key &key);
void Wipe();

/// How many entries are here
size_t Size() { return keys.size(); }

//Serialization hook
template<typename Archive>
void serialize(Archive &ar, const unsigned int version) {
ar & keys;
ar & capacities;
}

//InfoInterface function
void sstr(std::stringstream &ss, int depth, int indent) const override;
};

} // namespace kelpie

#endif //FAODEL_OBJECTCAPACITIES_HH
19 changes: 2 additions & 17 deletions src/kelpie/common/Types.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 National Technology & Engineering Solutions of Sandia,
// Copyright 2021 National Technology & Engineering Solutions of Sandia,
// LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.

Expand All @@ -14,6 +14,7 @@
#include "lunasa/DataObject.hh"

#include "kelpie/Key.hh"
#include "kelpie/common/ObjectCapacities.hh"

#include <boost/serialization/vector.hpp> //For packing ObjectCapacities

Expand Down Expand Up @@ -138,22 +139,6 @@ struct PoolBehavior {
};


class ObjectCapacities {
public:
std::vector<kelpie::Key> keys;
std::vector<size_t> capacities;

void Append(const ObjectCapacities &other) {
keys.insert(keys.end(), other.keys.begin(), other.keys.end());
capacities.insert(capacities.end(), other.capacities.begin(), other.capacities.end());
}
//Serialization hook
template <typename Archive>
void serialize(Archive &ar, const unsigned int version){
ar & keys;
ar & capacities;
}
};



Expand Down

0 comments on commit 7dc8d2d

Please sign in to comment.