lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [5093] Remove the problem identified 20100806T0945Z


From: Greg Chicares
Subject: [lmi-commits] [5093] Remove the problem identified 20100806T0945Z
Date: Fri, 06 Aug 2010 13:12:35 +0000

Revision: 5093
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5093
Author:   chicares
Date:     2010-08-06 13:12:35 +0000 (Fri, 06 Aug 2010)
Log Message:
-----------
Remove the problem identified 20100806T0945Z

Modified Paths:
--------------
    lmi/trunk/database.cpp
    lmi/trunk/database.hpp

Modified: lmi/trunk/database.cpp
===================================================================
--- lmi/trunk/database.cpp      2010-08-06 09:45:47 UTC (rev 5092)
+++ lmi/trunk/database.cpp      2010-08-06 13:12:35 UTC (rev 5093)
@@ -81,11 +81,20 @@
 {
 }
 
+/// Number of years to maturity for default lookup index.
+///
+/// Almost all database queries use the default index, so caching this
+/// value improves performance. For a query with an overridden index
+/// that modifies issue age, the cached value is incorrect, so Query()
+/// never relies on it.
+
 int product_database::length() const
 {
     return length_;
 }
 
+/// Default lookup index for database queries.
+
 database_index product_database::index() const
 {
     return index_;
@@ -130,17 +139,19 @@
 
 void product_database::Query(std::vector<double>& dst, e_database_key k, 
database_index const& i) const
 {
+    int const local_length = maturity_age_ - 
i.index_vector()[e_axis_issue_age];
+    LMI_ASSERT(0 < local_length && local_length <= methuselah);
     database_entity const& v = entity_from_key(k);
     double const*const z = v[i];
     if(1 == v.extent())
         {
-        dst.assign(length_, *z);
+        dst.assign(local_length, *z);
         }
     else
         {
-        dst.reserve(length_);
-        dst.assign(z, z + std::min(length_, v.extent()));
-        dst.resize(length_, dst.back());
+        dst.reserve(local_length);
+        dst.assign(z, z + std::min(local_length, v.extent()));
+        dst.resize(local_length, dst.back());
         }
 }
 
@@ -169,6 +180,10 @@
     return 1 != entity_from_key(k).axis_lengths().at(e_axis_state);
 }
 
+/// Initialize upon construction.
+///
+/// Set maturity age and default length (number of years to maturity).
+
 void product_database::initialize(std::string const& product_name)
 {
     if(is_antediluvian_fork())
@@ -180,11 +195,13 @@
         std::string 
filename(product_data(product_name).datum("DatabaseFilename"));
         DBDictionary::instance().Init(AddDataDir(filename));
         }
-    int const maturity_age = static_cast<int>(Query(DB_MaturityAge));
-    length_ = maturity_age - index_.index_vector()[e_axis_issue_age];
+    maturity_age_ = static_cast<int>(Query(DB_MaturityAge));
+    length_ = maturity_age_ - index_.index_vector()[e_axis_issue_age];
     LMI_ASSERT(0 < length_ && length_ <= methuselah);
 }
 
+/// Database entity corresponding to the given key.
+
 database_entity const& product_database::entity_from_key(e_database_key k) 
const
 {
     DBDictionary const& db = DBDictionary::instance();

Modified: lmi/trunk/database.hpp
===================================================================
--- lmi/trunk/database.hpp      2010-08-06 09:45:47 UTC (rev 5092)
+++ lmi/trunk/database.hpp      2010-08-06 13:12:35 UTC (rev 5093)
@@ -81,6 +81,7 @@
 
     database_index  index_;
     int             length_;
+    int             maturity_age_;
 };
 
 #endif // database_hpp




reply via email to

[Prev in Thread] Current Thread [Next in Thread]