Skip to content

Commit

Permalink
Merge branch 'master' into fresh-prefab
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 authored Dec 4, 2020
2 parents f618977 + 41b9a6b commit 75f99d4
Show file tree
Hide file tree
Showing 27 changed files with 254 additions and 126 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
deploy-dockerhub:
name: Deploy to DockerHub
runs-on: ubuntu-16.04
if: github.ref == 'refs/heads/master'
needs:
- test
- test-web
Expand Down
9 changes: 7 additions & 2 deletions doc/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

===============================================================================
This repository also contains the source code for C3.js (https://github.com/c3js/c3), which is available
This repository also contains the source code for C3.js (https://github.com/c3js/c3), which is available
under the MIT License:

The MIT License (MIT)
Expand All @@ -84,7 +84,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

===============================================================================

This repository also contains the source code for d3-tip.js (https://github.com/Caged/d3-tip), which is available
This repository also contains the source code for d3-tip.js (https://github.com/Caged/d3-tip), which is available
under the MIT License:

The MIT License (MIT)
Expand All @@ -108,3 +108,8 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

===============================================================================

This repository contains source code adapted from the LLVM Project, under the
Apache License v2.0 with LLVM Exceptions. See https://llvm.org/LICENSE.txt for
license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
6 changes: 3 additions & 3 deletions include/emp/bits/BitSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/


#ifndef EMP_BIT_SET_H
#define EMP_BIT_SET_H
#ifndef EMP_BIT_SET_HPP
#define EMP_BIT_SET_HPP

#include <iostream>
#include <initializer_list>
Expand Down Expand Up @@ -1430,4 +1430,4 @@ namespace std {
}


#endif
#endif // #ifndef EMP_BIT_SET_HPP
51 changes: 0 additions & 51 deletions include/emp/datastructs/AlignedCharArrayUnion.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#pragma once
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2020
*
* @file SmallFifoMap.hpp
* @brief Store key value pairs in a fixed-sized array, bumping out the oldest
* value when full. Optimized for small N. Requires N < 256.
*
*/

#ifndef EMP_ASSOCIATIVE_ARRAY_CACHE_HPP
#define EMP_ASSOCIATIVE_ARRAY_CACHE_HPP

#include <algorithm>
#include <utility>
Expand All @@ -10,7 +22,7 @@
namespace emp {

template<class Key, class Value, size_t N>
class AssociativeArrayCache {
class SmallFifoMap {

using value_type = std::pair<Key, Value>;

Expand All @@ -22,6 +34,7 @@ class AssociativeArrayCache {

unsigned char size_{};

// index of stalest element in cache, according to insertion order
unsigned char oldest{};

static_assert( N < 256 );
Expand All @@ -44,36 +57,55 @@ class AssociativeArrayCache {

const_iterator cend() const { return cbegin() + size(); }

/// How many key-value pairs are in the cache?
size_t size() const { return size_; }

/// Does the cache contain any key-value pairs?
bool empty() const { return size() == 0; }

/// How many key-value pairs can the cache contain?
static constexpr size_t capacity() { return N; }

/// Clear the cache.
void clear() { size_ = 0; }

public:

/// Find key-value pair iterator in cache.
iterator find(const Key& key) { return std::find_if(
begin(),
end(),
[&key](const auto& kv){ const auto& [k, v] = kv; return k == key; }
); }

/// Find key-value pair iterator in cache.
const_iterator find(const Key& key) const {
return const_cast<AssociativeArrayCache*>(this)->find(key);
return const_cast<SmallFifoMap*>(this)->find(key);
}

/// Get corresponding value from cache. Return nullptr if key not in cache.
Value* get(const Key& key) {
const auto it = find( key );
if ( it == end() ) return nullptr;
return std::addressof( it->second );
}

/// Get corresponding value from cache. Return nullptr if key not in cache.
Value const* get(const Key& key) const {
return const_cast<AssociativeArrayCache*>(this)->get( key );
return const_cast<SmallFifoMap*>(this)->get( key );
}

/// Get corresponding value from cache.
Value& operator[](const Key& key) {
const auto it = find( key );
emp_assert( it != end() );
return it->second;
}

/// Get corresponding value from cache.
const Value& operator[](const Key& key) const {
return const_cast<SmallFifoMap*>(this)->operator[]( key );
}

/// Put a key-value pair in the cache.
template<
class K,
class V,
Expand All @@ -97,3 +129,5 @@ class AssociativeArrayCache {
};

} // namespace emp

#endif // #ifndef EMP_ASSOCIATIVE_ARRAY_CACHE_HPP
74 changes: 54 additions & 20 deletions include/emp/datastructs/SmallVector.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
//===- emp/ADT/SmallVector.h - 'Normally small' vectors --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://emp.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the SmallVector class.
//
//===----------------------------------------------------------------------===//

#ifndef EMP_SMALL_VECTOR_H
#define EMP_SMALL_VECTOR_H

// #include "emp/Support/MathExtras.h"
// #include "emp/Support/type_traits.h"
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2020
*
* @file SmallVector.hpp
* @brief A drop-in replacement for std::vector with optimization to handle
* small vector sizes without dynamic allocation. It contains some number of
* elements in-place, which allows it to avoid heap allocation when the actual
* number of elements is below that threshold. This allows normal "small"
* cases to be fast without losing generality for large inputs.
*
* @note Adapted from the LLVM Project, under the Apache License v2.0 with
* LLVM Exceptions. See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#ifndef EMP_SMALL_VECTOR_HPP
#define EMP_SMALL_VECTOR_HPP

#include <algorithm>
#include <cassert>
#include <cstddef>
Expand All @@ -30,10 +33,41 @@
#include "../base/assert.hpp"
#include "../math/math.hpp"

#include "AlignedCharArrayUnion.hpp"

namespace emp {

// helpers for AlignedCharArrayUnion
namespace detail {

template <typename T, typename... Ts> class AlignerImpl {
T t;
AlignerImpl<Ts...> rest;
AlignerImpl() = delete;
};

template <typename T> class AlignerImpl<T> {
T t;
AlignerImpl() = delete;
};

template <typename T, typename... Ts> union SizerImpl {
char arr[sizeof(T)];
SizerImpl<Ts...> rest;
};

template <typename T> union SizerImpl<T> { char arr[sizeof(T)]; };
} // end namespace detail

/// A suitably aligned and sized character array member which can hold elements
/// of any type.
///
/// These types may be arrays, structs, or any other types. This exposes a
/// `buffer` member which can be used as suitable storage for a placement new of
/// any of these types.
template <typename T, typename... Ts> struct AlignedCharArrayUnion {
alignas(::emp::detail::AlignerImpl<T, Ts...>) char buffer[sizeof(
emp::detail::SizerImpl<T, Ts...>)];
};

/// This is all the non-templated stuff common to all SmallVectors.
class SmallVectorBase {
protected:
Expand Down Expand Up @@ -940,4 +974,4 @@ namespace std {

} // end namespace std

#endif // EMP_SMALL_VECTOR_H
#endif // EMP_SMALL_VECTOR_HPP
7 changes: 3 additions & 4 deletions include/emp/matching/MatchBin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
*
*/


#ifndef EMP_MATCH_BIN_H
#define EMP_MATCH_BIN_H
#ifndef EMP_MATCH_BIN_HPP
#define EMP_MATCH_BIN_HPP

// the default log filename can be set by passing
// '-D filename.csv' to the compiler
Expand Down Expand Up @@ -1003,4 +1002,4 @@ void load(

} // namespace cereal

#endif
#endif // #ifndef EMP_MATCH_BIN_HPP
22 changes: 18 additions & 4 deletions include/emp/matching/MatchDepository.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#pragma once
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2020
*
* @file MatchDepository.hpp
* @brief A container for tag-based lookup, optimized for situations where
* tags are not removed from the lookup set.
*
*/

#ifndef EMP_MATCH_DEPOSITORY_HPP
#define EMP_MATCH_DEPOSITORY_HPP

#include <algorithm>
#include <limits>

#include "../datastructs/AssociativeArrayCache.hpp"
#include "../datastructs/SmallFifoMap.hpp"
#include "../datastructs/SmallVector.hpp"

#include "_DepositoryEntry.hpp"
Expand Down Expand Up @@ -34,10 +46,10 @@ template<
emp::vector< emp::internal::DepositoryEntry<Val, tag_t, Regulator> > data;

// Cache of match results without regulation.
emp::AssociativeArrayCache< query_t, res_t, RawCacheSize > cache_raw;
emp::SmallFifoMap< query_t, res_t, RawCacheSize > cache_raw;

// Cache of match results with regulation.
emp::AssociativeArrayCache<query_t, res_t, RegulatedCacheSize>cache_regulated;
emp::SmallFifoMap< query_t, res_t, RegulatedCacheSize > cache_regulated;

/// Perform matching with regulation.
res_t DoRegulatedMatch( const query_t& query ) {
Expand Down Expand Up @@ -219,3 +231,5 @@ template<
};

} // namespace emp

#endif // #ifndef EMP_MATCH_DEPOSITORY_HPP
15 changes: 14 additions & 1 deletion include/emp/matching/_DepositoryEntry.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#pragma once
/**
* @note This file is part of Empirical, https://github.com/devosoft/Empirical
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2020
*
* @file DepositoryEntry.hpp
* @brief Helper struct for MatchDepository.
*
*/

#ifndef EMP_DEPOSITORY_ENTRY_HPP
#define EMP_DEPOSITORY_ENTRY_HPP

namespace emp {
namespace internal {
Expand All @@ -16,3 +27,5 @@ struct DepositoryEntry {

} // namespace internal
} // namespace emp

#endif // #ifndef EMP_DEPOSITORY_ENTRY_HPP
Loading

0 comments on commit 75f99d4

Please sign in to comment.