summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2017-02-17 17:15:41 (GMT)
committerTobias Markmann <tm@ayena.de>2017-02-22 10:54:22 (GMT)
commiteea861301be0bf3e3f5db6cfc3cada38d133fef2 (patch)
tree3c2aa07ce3724a73ce2124832bee6b8c7884c9df /3rdParty/Boost/src/boost/multi_index/detail/index_saver.hpp
parent80801aaeba2d29e3a375a01d782cf081e778dfaf (diff)
downloadswift-eea861301be0bf3e3f5db6cfc3cada38d133fef2.zip
swift-eea861301be0bf3e3f5db6cfc3cada38d133fef2.tar.bz2
Add LRUCache utility class to Swiften
This implements a simple lookup cache with least recently used replacement strategy. This also adds Boost.MultiIndex from version 1.56 to 3rdParty. Test-Information: Added some unit tests for LRUCache, which pass on macOS 10.12.3 with clang-5.0 Change-Id: I0567945b1197d3fe786bf9d82fdb5e755743b975
Diffstat (limited to '3rdParty/Boost/src/boost/multi_index/detail/index_saver.hpp')
-rw-r--r--3rdParty/Boost/src/boost/multi_index/detail/index_saver.hpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/3rdParty/Boost/src/boost/multi_index/detail/index_saver.hpp b/3rdParty/Boost/src/boost/multi_index/detail/index_saver.hpp
new file mode 100644
index 0000000..ae09d4e
--- /dev/null
+++ b/3rdParty/Boost/src/boost/multi_index/detail/index_saver.hpp
@@ -0,0 +1,135 @@
+/* Copyright 2003-2013 Joaquin M Lopez Munoz.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/multi_index for library home page.
+ */
+
+#ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_SAVER_HPP
+#define BOOST_MULTI_INDEX_DETAIL_INDEX_SAVER_HPP
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
+#include <boost/multi_index/detail/index_matcher.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/serialization/nvp.hpp>
+#include <cstddef>
+
+namespace boost{
+
+namespace multi_index{
+
+namespace detail{
+
+/* index_saver accepts a base sequence of previously saved elements
+ * and saves a possibly reordered subsequence in an efficient manner,
+ * serializing only the information needed to rearrange the subsequence
+ * based on the original order of the base.
+ * multi_index_container is in charge of supplying the info about the
+ * base sequence, and each index can subsequently save itself using the
+ * const interface of index_saver.
+ */
+
+template<typename Node,typename Allocator>
+class index_saver:private noncopyable
+{
+public:
+ index_saver(const Allocator& al,std::size_t size):alg(al,size){}
+
+ template<class Archive>
+ void add(Node* node,Archive& ar,const unsigned int)
+ {
+ ar<<serialization::make_nvp("position",*node);
+ alg.add(node);
+ }
+
+ template<class Archive>
+ void add_track(Node* node,Archive& ar,const unsigned int)
+ {
+ ar<<serialization::make_nvp("position",*node);
+ }
+
+ template<typename IndexIterator,class Archive>
+ void save(
+ IndexIterator first,IndexIterator last,Archive& ar,
+ const unsigned int)const
+ {
+ /* calculate ordered positions */
+
+ alg.execute(first,last);
+
+ /* Given a consecutive subsequence of displaced elements
+ * x1,...,xn, the following information is serialized:
+ *
+ * p0,p1,...,pn,0
+ *
+ * where pi is a pointer to xi and p0 is a pointer to the element
+ * preceding x1. Crealy, from this information is possible to
+ * restore the original order on loading time. If x1 is the first
+ * element in the sequence, the following is serialized instead:
+ *
+ * p1,p1,...,pn,0
+ *
+ * For each subsequence of n elements, n+2 pointers are serialized.
+ * An optimization policy is applied: consider for instance the
+ * sequence
+ *
+ * a,B,c,D
+ *
+ * where B and D are displaced, but c is in its correct position.
+ * Applying the schema described above we would serialize 6 pointers:
+ *
+ * p(a),p(B),0
+ * p(c),p(D),0
+ *
+ * but this can be reduced to 5 pointers by treating c as a displaced
+ * element:
+ *
+ * p(a),p(B),p(c),p(D),0
+ */
+
+ std::size_t last_saved=3; /* distance to last pointer saved */
+ for(IndexIterator it=first,prev=first;it!=last;prev=it++,++last_saved){
+ if(!alg.is_ordered(get_node(it))){
+ if(last_saved>1)save_node(get_node(prev),ar);
+ save_node(get_node(it),ar);
+ last_saved=0;
+ }
+ else if(last_saved==2)save_node(null_node(),ar);
+ }
+ if(last_saved<=2)save_node(null_node(),ar);
+
+ /* marks the end of the serialization info for [first,last) */
+
+ save_node(null_node(),ar);
+ }
+
+private:
+ template<typename IndexIterator>
+ static Node* get_node(IndexIterator it)
+ {
+ return it.get_node();
+ }
+
+ static Node* null_node(){return 0;}
+
+ template<typename Archive>
+ static void save_node(Node* node,Archive& ar)
+ {
+ ar<<serialization::make_nvp("pointer",node);
+ }
+
+ index_matcher::algorithm<Node,Allocator> alg;
+};
+
+} /* namespace multi_index::detail */
+
+} /* namespace multi_index */
+
+} /* namespace boost */
+
+#endif