mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Validators work
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
#ifndef RIPPLE_VALIDATORS_TUNING_H_INCLUDED
|
||||
#define RIPPLE_VALIDATORS_TUNING_H_INCLUDED
|
||||
|
||||
#include <boost/version.hpp>
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
@@ -41,22 +43,31 @@ enum
|
||||
// This tunes the preallocated arrays
|
||||
,expectedNumberOfResults = 1000
|
||||
|
||||
// How many elements in the aged history before we swap containers
|
||||
,maxSizeBeforeSwap = 100
|
||||
// NUmber of entries in the seen validations cache
|
||||
,seenValidationsCacheSize = 1000
|
||||
|
||||
// Number of entries in the seen ledgers cache
|
||||
,seenLedgersCacheSize = 1000 // about half an hour at 2/sec
|
||||
|
||||
// Number of closed Ledger entries per Validator
|
||||
,ledgersPerValidator = 100 // this shouldn't be too large
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Associative container of unique keys. */
|
||||
/** Cycled associative map of unique keys. */
|
||||
template <class Key,
|
||||
class T,
|
||||
class Hash = typename Key::hasher, // class Hash = boost::hash <Key>
|
||||
class Info, // per-container info
|
||||
class Hash = typename Key::hasher,
|
||||
class KeyEqual = std::equal_to <Key>,
|
||||
class Allocator = std::allocator <std::pair <const Key, T> > >
|
||||
class Allocator = std::allocator <Key> >
|
||||
class CycledMap
|
||||
{
|
||||
private:
|
||||
typedef boost::unordered_map <Key, T, Hash, KeyEqual, Allocator> ContainerType;
|
||||
typedef boost::unordered_map <
|
||||
Key, T, Hash, KeyEqual, Allocator> ContainerType;
|
||||
typedef typename ContainerType::iterator iterator;
|
||||
|
||||
public:
|
||||
typedef typename ContainerType::key_type key_type;
|
||||
@@ -64,34 +75,97 @@ public:
|
||||
typedef typename ContainerType::size_type size_type;
|
||||
typedef typename ContainerType::difference_type difference_type;
|
||||
typedef typename ContainerType::hasher hasher;
|
||||
typedef typename ContainerType::key_equal key_equal;
|
||||
typedef typename ContainerType::allocator_type allocator_type;
|
||||
typedef typename ContainerType::reference reference;
|
||||
typedef typename ContainerType::const_reference const_reference;
|
||||
typedef typename ContainerType::pointer pointer;
|
||||
typedef typename ContainerType::const_pointer const_pointer;
|
||||
|
||||
explicit CycledMap (
|
||||
size_type item_max,
|
||||
Hash hash = Hash(),
|
||||
KeyEqual equal = KeyEqual(),
|
||||
Allocator alloc = Allocator())
|
||||
: m_max (item_max)
|
||||
, m_hash (hash)
|
||||
, m_equal (equal)
|
||||
, m_alloc (alloc)
|
||||
, m_front (m_max, hash, equal, alloc)
|
||||
, m_back (m_max, hash, equal, alloc)
|
||||
{
|
||||
}
|
||||
|
||||
Info& front()
|
||||
{ return m_front_info; }
|
||||
|
||||
Info const & front() const
|
||||
{ return m_front_info; }
|
||||
|
||||
Info& back ()
|
||||
{ return m_back_info; }
|
||||
|
||||
Info const& back () const
|
||||
{ return m_back_info; }
|
||||
|
||||
/** Returns `true` if the next real insert would swap. */
|
||||
bool full() const
|
||||
{
|
||||
return m_front.size() >= m_max;
|
||||
}
|
||||
|
||||
/** Insert the value if it doesn't already exist. */
|
||||
std::pair <T&, Info&> insert (value_type const& value)
|
||||
{
|
||||
if (full())
|
||||
cycle ();
|
||||
iterator iter (m_back.find (value.first));
|
||||
if (iter != m_back.end())
|
||||
return std::make_pair (
|
||||
boost::ref (iter->second),
|
||||
boost::ref (m_back_info));
|
||||
std::pair <iterator, bool> result (
|
||||
m_front.insert (value));
|
||||
return std::make_pair (
|
||||
boost::ref (result.first->second),
|
||||
boost::ref (m_front_info));
|
||||
}
|
||||
|
||||
void cycle ()
|
||||
{
|
||||
m_front.clear ();
|
||||
std::swap (m_front, m_back);
|
||||
m_front.clear ();
|
||||
#if BOOST_VERSION > 105400
|
||||
m_front.reserve (m_max);
|
||||
#endif
|
||||
std::swap (m_front_info, m_back_info);
|
||||
m_front_info.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
size_type m_max;
|
||||
hasher m_hash;
|
||||
key_equal m_equal;
|
||||
allocator_type m_alloc;
|
||||
ContainerType m_front;
|
||||
ContainerType m_back;
|
||||
Info m_front_info;
|
||||
Info m_back_info;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Associative container of unique keys. */
|
||||
/** Cycled set of unique keys. */
|
||||
template <class Key,
|
||||
class Hash = typename Key::hasher, // class Hash = boost::hash <Key>
|
||||
class Hash = typename Key::hasher,
|
||||
class KeyEqual = std::equal_to <Key>,
|
||||
class Allocator = std::allocator <Key> >
|
||||
class CycledSet
|
||||
{
|
||||
private:
|
||||
typedef boost::unordered_set <Key, Hash, KeyEqual, Allocator> ContainerType;
|
||||
typedef boost::unordered_set <
|
||||
Key, Hash, KeyEqual, Allocator> ContainerType;
|
||||
typedef typename ContainerType::iterator iterator;
|
||||
|
||||
public:
|
||||
typedef typename ContainerType::key_type key_type;
|
||||
@@ -115,23 +189,47 @@ public:
|
||||
, m_hash (hash)
|
||||
, m_equal (equal)
|
||||
, m_alloc (alloc)
|
||||
, m_front (hash, equal, alloc)
|
||||
, m_back (hash, equal, alloc)
|
||||
, m_front (m_max, hash, equal, alloc)
|
||||
, m_back (m_max, hash, equal, alloc)
|
||||
{
|
||||
m_front.reserve (m_max);
|
||||
m_back.reserve (m_max);
|
||||
}
|
||||
|
||||
// Returns `true` if the next real insert would swap
|
||||
bool full() const
|
||||
{
|
||||
return m_front.size() >= m_max;
|
||||
}
|
||||
|
||||
// Adds the key to the front if its not in either map
|
||||
bool insert (key_type const& key)
|
||||
{
|
||||
if (full())
|
||||
cycle ();
|
||||
if (m_back.find (key) != m_back.end())
|
||||
return false;
|
||||
std::pair <iterator, bool> result (
|
||||
m_front.insert (key));
|
||||
if (result.second)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool find (key_type const& key)
|
||||
{
|
||||
if (m_front.find (key) != m_front.end())
|
||||
return true;
|
||||
return m_back.find (key) != m_back.end();
|
||||
}
|
||||
#endif
|
||||
|
||||
void cycle ()
|
||||
{
|
||||
m_front.clear ();
|
||||
std::swap (m_front, m_back);
|
||||
}
|
||||
|
||||
bool insert (value_type const& value)
|
||||
{
|
||||
std::size_t const hash (m_hash (value));
|
||||
|
||||
m_front.clear ();
|
||||
#if BOOST_VERSION > 105400
|
||||
m_front.reserve (m_max);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user