From 0da2b7fe79ac1610a0a8b6809f967d056881747c Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Fri, 20 Oct 2000 05:01:34 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/downloader/downloadDb.cxx | 35 ++++++++++++++++++++++++----- panda/src/downloader/downloadDb.h | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/panda/src/downloader/downloadDb.cxx b/panda/src/downloader/downloadDb.cxx index 97d2f99426..b3b386aa8e 100644 --- a/panda/src/downloader/downloadDb.cxx +++ b/panda/src/downloader/downloadDb.cxx @@ -936,7 +936,7 @@ output(ostream &out) const { void DownloadDb:: add_version(const Filename &name, Hash hash, Version version) { int name_code = atoi(name.get_fullpath().c_str()); - _versions[name_code][version] = hash; + add_version(name_code, hash, version); } //////////////////////////////////////////////////////////////////// @@ -945,8 +945,29 @@ add_version(const Filename &name, Hash hash, Version version) { // Description: //////////////////////////////////////////////////////////////////// void DownloadDb:: -add_version(int name, Hash hash, Version version) { - _versions[name][version] = hash; +add_version(int name_code, Hash hash, Version version) { + // Try to find this name_code in the map + VersionMap::iterator i = _versions.find(name_code); + + // If we did not find it, put a new vector_ulong at this name_code + if (i == _versions.end()) { + vector_ulong v; + v.push_back(hash); + _versions[name_code] = v; + } else { + int size = (*i).second.size(); + + // Assert that this version is the next version in the list + nassertv(version<=size); + + // If you are overwriting an old hash value, just insert the new value + if (version < size) { + (*i).second[version] = hash; + } else { + // add this hash at the end of the vector + (*i).second.push_back(hash); + } + } } //////////////////////////////////////////////////////////////////// @@ -957,10 +978,14 @@ add_version(int name, Hash hash, Version version) { int DownloadDb:: get_version(const Filename &name, Hash hash) { int name_code = atoi(name.get_fullpath().c_str()); - vector_ulong ulvec = _versions[name_code]; + VersionMap::const_iterator vmi = _versions.find(name_code); + if (vmi == _versions.end()) { + return -1; + } + vector_ulong ulvec = (*vmi).second; vector_ulong::iterator i = find(ulvec.begin(), ulvec.end(), hash); if (i != ulvec.end()) - return (ulvec.begin() - i); + return (i - ulvec.begin()); return -1; } diff --git a/panda/src/downloader/downloadDb.h b/panda/src/downloader/downloadDb.h index 5dcc19de91..5d3ff4a927 100644 --- a/panda/src/downloader/downloadDb.h +++ b/panda/src/downloader/downloadDb.h @@ -203,7 +203,7 @@ public: typedef vector vector_ulong; typedef map VersionMap; void add_version(const Filename &name, Hash hash, Version version); - void add_version(int name, Hash hash, Version version); + void add_version(int name_code, Hash hash, Version version); int get_version(const Filename &name, Hash hash); protected: