[Liblas-commits] libpc: rename lru cache

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Mar 11 15:10:39 EST 2011


details:   http://hg.liblas.orglibpc/rev/fd4ac5407792
changeset: 211:fd4ac5407792
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Mar 11 09:29:21 2011 -0800
description:
rename lru cache
Subject: libpc: bringing lru cache online

details:   http://hg.liblas.orglibpc/rev/fe4542b1268e
changeset: 212:fe4542b1268e
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Mar 11 12:10:23 2011 -0800
description:
bringing lru cache online
Subject: libpc: merge

details:   http://hg.liblas.orglibpc/rev/c9d6c4e418fc
changeset: 213:c9d6c4e418fc
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Fri Mar 11 12:10:33 2011 -0800
description:
merge

diffstat:

 apps/pc2pc.cpp                   |    7 +-
 include/libpc/CacheFilter.hpp    |    4 +
 include/libpc/LruCache.hpp       |  162 -----------------------------------
 include/libpc/PointDataCache.hpp |  179 +++++++++++++++++++++++++++++++++++++++
 src/CMakeLists.txt               |    3 +-
 src/CacheFilter.cpp              |   78 ++++++++++------
 src/Filter.cpp                   |    4 +-
 src/PointDataCache.cpp           |   16 +++
 test/unit/CMakeLists.txt         |    2 +-
 test/unit/CacheFilterTest.cpp    |   56 ++++++-----
 test/unit/LruCacheTest.cpp       |  116 -------------------------
 test/unit/PointDataCacheTest.cpp |   85 ++++++++++++++++++
 12 files changed, 368 insertions(+), 344 deletions(-)

diffs (truncated from 887 to 300 lines):

diff -r 379061fbe63b -r c9d6c4e418fc apps/pc2pc.cpp
--- a/apps/pc2pc.cpp	Fri Mar 11 09:23:19 2011 -0800
+++ b/apps/pc2pc.cpp	Fri Mar 11 12:10:33 2011 -0800
@@ -122,12 +122,13 @@
         writer.write(np);
     }
 
+#ifdef HAVE_ORACLE
 
     else if (hasOption("oracle"))
     {
 #ifdef HAVE_ORACLE
         LasReader reader(*ifs);
-        std::cout << "running oracle test" << std::endl;
+    
         const boost::uint64_t numPoints = reader.getHeader().getNumPoints();
         
         libpc::driver::oci::Options options;
@@ -149,12 +150,12 @@
 
         size_t np = (size_t)numPoints;
         assert(numPoints == np); // BUG
-         writer.write(np);
+        writer.write(np);
 #else
         throw configuration_error("libPC not compiled with Oracle support");
 #endif
     }    
-
+#endif
     else
     {
         LiblasReader reader(*ifs);
diff -r 379061fbe63b -r c9d6c4e418fc include/libpc/CacheFilter.hpp
--- a/include/libpc/CacheFilter.hpp	Fri Mar 11 09:23:19 2011 -0800
+++ b/include/libpc/CacheFilter.hpp	Fri Mar 11 12:10:33 2011 -0800
@@ -40,6 +40,8 @@
 namespace libpc
 {
 
+class PointDataCache;
+
 // This is just a very simple MRU filter -- future versions will be smarter.
 // This cache has the following constraints:
 //   - only one block is cached
@@ -74,6 +76,8 @@
     boost::uint64_t m_numPointsRequested;
     boost::uint64_t m_numPointsRead;
 
+    PointDataCache* m_cache;
+
     CacheFilter& operator=(const CacheFilter&); // not implemented
     CacheFilter(const CacheFilter&); // not implemented
 };
diff -r 379061fbe63b -r c9d6c4e418fc include/libpc/LruCache.hpp
--- a/include/libpc/LruCache.hpp	Fri Mar 11 09:23:19 2011 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 2010, Tim Day <timday at timday.com>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-// This code is from http://www.bottlenose.demon.co.uk/article/lru.htm.  It is
-// under a Internet Systems Consortium (ISC) license (an OSI-approved BSD-alike license).
-
-#ifndef INCLUDED_LIBPC_LRUCACHE_HPP
-#define INCLUDED_LIBPC_LRUCACHE_HPP
-
-
-#ifdef _MSC_VER
-#  pragma warning(push)
-#  pragma warning(disable: 4512)  // assignment operator could not be generated
-#endif
-#include <boost/bimap.hpp>
-#include <boost/bimap/list_of.hpp>
-#include <boost/bimap/set_of.hpp>
-#include <boost/function.hpp>
-#ifdef _MSC_VER
-#  pragma warning(pop)
-#endif
-
-namespace libpc
-{
-
-class PointData;
-
-
-class LruCache
-{
-public:
-
-    typedef int dummy_type;
-
-    // Bimap with key access on left view, key access
-    // history on right view, and associated value.
-    typedef boost::bimaps::bimap<
-    boost::bimaps::set_of<boost::uint32_t>,
-          boost::bimaps::list_of<dummy_type>,
-          boost::bimaps::with_info<PointData*>
-          > cache_type;
-
-    // Constuctor specifies the cached function and
-    // the maximum number of records to be stored.
-    LruCache(size_t c)
-        :_capacity(c)
-    {
-        assert(_capacity!=0);
-    }
-
-    ~LruCache()
-    {
-        for (cache_type::left_iterator it =_cache.left.begin(); it != _cache.left.end(); ++it)
-        {
-           PointData* data = it->info;
-           delete data;
-        }
-        return;
-    }
-
-    PointData* lookup(boost::uint32_t k)
-    {
-        // Attempt to find existing record
-        const cache_type::left_iterator it =_cache.left.find(k);
-
-        if (it==_cache.left.end())
-        {
-            // We don't have it:
-            return NULL;
-        }
-        else
-        {
-            // We do have it:
-            return it->info;
-        }
-    }
-
-    // Obtain value of the cached function for k
-    PointData* insert(boost::uint32_t k, PointData* v)
-    {
-        // Attempt to find existing record
-        const cache_type::left_iterator it =_cache.left.find(k);
-
-        if (it==_cache.left.end())
-        {
-            // We don't have it: insert it
-            insertx(k,v);
-            return v;
-        }
-        else
-        {
-            // We do have it:
-            // Update the access record view.
-            _cache.right.relocate(
-                _cache.right.end(),
-                _cache.project_right(it)
-            );
-
-            return it->info;
-        }
-    }
-
-    // Obtain the cached keys, most recently used element
-    // at head, least recently used at tail.
-    // This method is provided purely to support testing.
-    template <typename IT> void get_keys(IT dst) const
-    {
-        typename cache_type::right_const_reverse_iterator src
-        =_cache.right.rbegin();
-        while (src!=_cache.right.rend())
-        {
-            dst=(*src).second;
-            ++src;
-            ++dst;
-        }
-    }
-
-private:
-
-    void insertx(boost::uint32_t k, PointData* v)
-    {
-        assert(_cache.size()<=_capacity);
-
-        // If necessary, make space
-        if (_cache.size()==_capacity)
-        {
-            // by purging the least-recently-used element
-            _cache.right.erase(_cache.right.begin());
-        }
-
-        // Create a new record from the key, a dummy and the value
-        _cache.insert(
-            cache_type::value_type(
-                k,0,v
-            )
-        );
-    }
-
-    const size_t _capacity;
-    cache_type _cache;
-
-    LruCache& operator=(const LruCache&); // not implemented
-    LruCache(const LruCache&); // not implemented
-};
-
-
-} // namespace
-
-#endif
diff -r 379061fbe63b -r c9d6c4e418fc include/libpc/PointDataCache.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/libpc/PointDataCache.hpp	Fri Mar 11 12:10:33 2011 -0800
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2010, Tim Day <timday at timday.com>
+ * Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+// This PointData-specific code derived from the templated code at
+// http://www.bottlenose.demon.co.uk/article/lru.htm.  It is under an
+// Internet Systems Consortium (ISC) license (an OSI-approved BSD-alike license).
+
+#ifndef INCLUDED_LIBPC_POINTDATACACHE_HPP
+#define INCLUDED_LIBPC_POINTDATACACHE_HPP
+
+
+#ifdef _MSC_VER
+#  pragma warning(push)
+#  pragma warning(disable: 4512)  // assignment operator could not be generated
+#endif
+#include <boost/bimap.hpp>
+#include <boost/bimap/list_of.hpp>
+#include <boost/bimap/set_of.hpp>
+#include <boost/function.hpp>
+#ifdef _MSC_VER
+#  pragma warning(pop)
+#endif
+
+#include "libpc/PointData.hpp"
+
+
+namespace libpc
+{
+
+
+class PointDataCache
+{
+public:
+
+    typedef int dummy_type;
+
+    // Bimap with key access on left view, key access
+    // history on right view, and associated value.
+    typedef boost::bimaps::bimap<
+    boost::bimaps::set_of<boost::uint64_t>,
+          boost::bimaps::list_of<dummy_type>,
+          boost::bimaps::with_info<PointData*>
+          > cache_type;
+
+    // Constuctor specifies the cached function and
+    // the maximum number of records to be stored.
+    PointDataCache(size_t c)
+        :_capacity(c)
+    {
+        assert(_capacity!=0);
+    }
+
+    ~PointDataCache()
+    {
+        for (cache_type::left_iterator it =_cache.left.begin(); it != _cache.left.end(); ++it)
+        {
+           PointData* data = it->info;
+           delete data;
+        }
+        return;
+    }
+


More information about the Liblas-commits mailing list