]> git.donarmstrong.com Git - bamtools.git/commitdiff
Removed data duplication in last update to Sam*Dictionaries
authorderek <derekwbarnett@gmail.com>
Sun, 16 Oct 2011 05:48:00 +0000 (01:48 -0400)
committerderek <derekwbarnett@gmail.com>
Sun, 16 Oct 2011 05:48:00 +0000 (01:48 -0400)
CMakeLists.txt
docs/Doxyfile
src/api/CMakeLists.txt
src/api/SamReadGroupDictionary.cpp
src/api/SamReadGroupDictionary.h
src/api/SamSequenceDictionary.cpp
src/api/SamSequenceDictionary.h

index bcbdb3f493c2602a2bd55cb8049a7354e4475e13..bc61435f95b39105786210f94f398e3ae022aae6 100644 (file)
@@ -32,7 +32,7 @@ ensure_out_of_source_build ("
 # set BamTools version information
 set (BamTools_VERSION_MAJOR 2)
 set (BamTools_VERSION_MINOR 0)
-set (BamTools_VERSION_BUILD 3)
+set (BamTools_VERSION_BUILD 4)
 
 # set our library and executable destination dirs
 set (EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
index 6e882dd5cead7310ebcc2661a3b810a745016981..b50929b5e550094107cbd16b55b8745182555559 100644 (file)
@@ -31,7 +31,7 @@ PROJECT_NAME           = BamTools
 # This could be handy for archiving the generated documentation or 
 # if some version control system is used.
 
-PROJECT_NUMBER         = 2.0.3
+PROJECT_NUMBER         = 2.0.4
 
 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
 # base path where the generated documentation will be put. 
index 3e2ddd5b022ac309a3f5e0dce80f8d36754485be..8278f66bac7a03752c27522cae574f2b65529a66 100644 (file)
@@ -49,7 +49,7 @@ set( BamToolsAPISources
 
 # create main BamTools API shared library
 add_library( BamTools SHARED ${BamToolsAPISources} )
-set_target_properties( BamTools PROPERTIES SOVERSION "2.0.3" )
+set_target_properties( BamTools PROPERTIES SOVERSION "2.0.4" )
 set_target_properties( BamTools PROPERTIES OUTPUT_NAME "bamtools" )
 
 # create main BamTools API static library
index 7e36a155cbf8a8166b3b4f095d5e24126e95fb99..007221a7cd030e0fd2a1d68e8086340d95a7e8e0 100644 (file)
@@ -2,7 +2,7 @@
 // SamReadGroupDictionary.cpp (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 14 October 2011 (DB)
+// Last modified: 16 October 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides methods for operating on a collection of SamReadGroup entries.
 // ***************************************************************************
@@ -47,7 +47,7 @@ SamReadGroupDictionary::~SamReadGroupDictionary(void) { }
 void SamReadGroupDictionary::Add(const SamReadGroup& readGroup) {
     if ( IsEmpty() || !Contains(readGroup) ) {
         m_data.push_back(readGroup);
-        m_lookupData[readGroup.ID] = readGroup;
+        m_lookupData[readGroup.ID] = m_data.size() - 1;
     }
 }
 
@@ -219,15 +219,20 @@ void SamReadGroupDictionary::Remove(const SamReadGroup& readGroup) {
 */
 void SamReadGroupDictionary::Remove(const std::string& readGroupId) {
 
-    SamReadGroupIterator rgIter = Begin();
-    SamReadGroupIterator rgEnd  = End();
-    for ( size_t i = 0 ; rgIter != rgEnd; ++rgIter, ++i ) {
-        SamReadGroup& rg = (*rgIter);
-        if( rg.ID == readGroupId ) {
-            m_data.erase( Begin() + i );
-        }
+    // skip if empty dictionary or if ID unknown
+    if ( IsEmpty() || !Contains(readGroupId) )
+        return;
+
+    // update 'lookup index' for every entry after @readGroupId
+    const size_t indexToRemove = m_lookupData[readGroupId];
+    const size_t numEntries = m_data.size();
+    for ( size_t i = indexToRemove+1; i < numEntries; ++i ) {
+        const SamReadGroup& rg = m_data.at(i);
+        --m_lookupData[rg.ID];
     }
 
+    // erase entry from containers
+    m_data.erase( Begin() + indexToRemove );
     m_lookupData.erase(readGroupId);
 }
 
@@ -280,10 +285,13 @@ int SamReadGroupDictionary::Size(void) const {
     \return a modifiable reference to the SamReadGroup associated with the ID
 */
 SamReadGroup& SamReadGroupDictionary::operator[](const std::string& readGroupId) {
+
     if ( !Contains(readGroupId) ) {
         SamReadGroup rg(readGroupId);
         m_data.push_back(rg);
-        m_lookupData[readGroupId] = rg;
+        m_lookupData[readGroupId] = m_data.size() - 1;
     }
-    return m_lookupData[readGroupId];
+
+    const size_t index = m_lookupData[readGroupId];
+    return m_data.at(index);
 }
index c66c6d5b233dee35648bfaf4b65d01ec257a9f0b..a4aeda95154d1f3c99372bf4a145ed15f3013892 100644 (file)
@@ -2,7 +2,7 @@
 // SamReadGroupDictionary.h (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 14 October 2011 (DB)
+// Last modified: 16 October 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides methods for operating on a collection of SamReadGroup entries.
 // ***************************************************************************
@@ -77,7 +77,7 @@ class API_EXPORT SamReadGroupDictionary {
     // data members
     private:
         SamReadGroupContainer m_data;
-        std::map<std::string, SamReadGroup> m_lookupData;
+        std::map<std::string, size_t> m_lookupData;
 };
 
 } // namespace BamTools
index 25694f34f723f053c192658817314fa058058a1c..5d2ab642651d41be80de7ffda8626d82e47541bb 100644 (file)
@@ -2,7 +2,7 @@
 // SamSequenceDictionary.cpp (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 14 October 2011 (DB)
+// Last modified: 16 October 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides methods for operating on a collection of SamSequence entries.
 // *************************************************************************
@@ -47,7 +47,7 @@ SamSequenceDictionary::~SamSequenceDictionary(void) { }
 void SamSequenceDictionary::Add(const SamSequence& sequence) {
     if ( IsEmpty() || !Contains(sequence) ) {
         m_data.push_back(sequence);
-        m_lookupData[sequence.Name] = sequence;
+        m_lookupData[sequence.Name] = m_data.size() - 1;
     }
 }
 
@@ -223,15 +223,20 @@ void SamSequenceDictionary::Remove(const SamSequence& sequence) {
 */
 void SamSequenceDictionary::Remove(const std::string& sequenceName) {
 
-    SamSequenceIterator seqIter = Begin();
-    SamSequenceIterator seqEnd  = End();
-    for ( size_t i = 0 ; seqIter != seqEnd; ++seqIter, ++i ) {
-        SamSequence& seq = (*seqIter);
-        if( seq.Name == sequenceName ) {
-            m_data.erase( Begin() + i );
-        }
+    // skip if empty dictionary or if name unknown
+    if ( IsEmpty() || !Contains(sequenceName) )
+        return;
+
+    // update 'lookup index' for every entry after @sequenceName
+    const size_t indexToRemove = m_lookupData[sequenceName];
+    const size_t numEntries = m_data.size();
+    for ( size_t i = indexToRemove+1; i < numEntries; ++i ) {
+        const SamSequence& sq = m_data.at(i);
+        --m_lookupData[sq.Name];
     }
 
+    // erase entry from containers
+    m_data.erase( Begin() + indexToRemove );
     m_lookupData.erase(sequenceName);
 }
 
@@ -284,10 +289,13 @@ int SamSequenceDictionary::Size(void) const {
     \return a modifiable reference to the SamSequence associated with the name
 */
 SamSequence& SamSequenceDictionary::operator[](const std::string& sequenceName) {
+
     if ( !Contains(sequenceName) ) {
         SamSequence seq(sequenceName, 0);
         m_data.push_back(seq);
-        m_lookupData[sequenceName] = seq;
+        m_lookupData[sequenceName] = m_data.size() - 1;
     }
-    return m_lookupData[sequenceName];
+
+    const size_t index = m_lookupData[sequenceName];
+    return m_data.at(index);
 }
index cf7c2f3eb4049fef90739a77e6c7ce6ba7556911..d267dbdac5db5182dcd9c100e076cac4298959eb 100644 (file)
@@ -2,7 +2,7 @@
 // SamSequenceDictionary.h (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 14 October 2011
+// Last modified: 16 October 2011
 // ---------------------------------------------------------------------------
 // Provides methods for operating on a collection of SamSequence entries.
 // ***************************************************************************
@@ -77,7 +77,7 @@ class API_EXPORT SamSequenceDictionary {
     // data members
     private:
         SamSequenceContainer m_data;
-        std::map<std::string, SamSequence> m_lookupData;
+        std::map<std::string, size_t> m_lookupData;
 };
 
 } // namespace BamTools