-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from faodel/kelpie/refactor-object-capacities
KELPIE: Update ObjectCapacities
- Loading branch information
Showing
5 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters