[Debtags-commits] [svn] r1576 - in tagcoll/trunk: . tagcoll
Enrico Zini
enrico at costa.debian.org
Mon Feb 13 15:35:16 UTC 2006
Author: enrico
Date: Mon Feb 13 15:35:14 2006
New Revision: 1576
Modified:
tagcoll/trunk/ (props changed)
tagcoll/trunk/tagcoll/IntIndex.h
tagcoll/trunk/tagcoll/StringIndex.cc
tagcoll/trunk/tagcoll/StringIndex.h
Log:
r7283 at viaza: enrico | 2006-02-13 13:28:29 +0100
Gracefully handle elements that are not present in the index.
Modified: tagcoll/trunk/tagcoll/IntIndex.h
==============================================================================
--- tagcoll/trunk/tagcoll/IntIndex.h (original)
+++ tagcoll/trunk/tagcoll/IntIndex.h Mon Feb 13 15:35:14 2006
@@ -46,20 +46,20 @@
* This allows fast lookups, as well as fast lookups of unions or intersections
* of mapped arrays.
*
- * This class tries to be a simple and fast component for building indexes, and
- * thus no bound checking is performed.
+ * The number of items for an ID not present in the index is assumed to be 0.
*/
class IntIndex : public MMapIndex
{
protected:
inline int* buf() const { return (int*)m_buf; }
+ inline size_t ofs(int val) const { return buf()[val]; }
public:
IntIndex(const std::string& filename) : MMapIndex(filename) {}
- const int* data(unsigned int val) const { return buf() + buf()[val] + 1; }
- unsigned int size(unsigned int val) const { return val < size() ? buf()[buf()[val]] : 0; }
- unsigned int size() const { return buf()[0]; }
+ const int* data(int val) const { return (val >= 0 && (unsigned)val < size()) ? buf() + ofs(val) + 1 : 0; }
+ size_t size(int val) const { return (val >= 0 && (unsigned)val < size()) ? buf()[ofs(val)] : 0; }
+ size_t size() const { return ofs(0); }
};
/**
Modified: tagcoll/trunk/tagcoll/StringIndex.cc
==============================================================================
--- tagcoll/trunk/tagcoll/StringIndex.cc (original)
+++ tagcoll/trunk/tagcoll/StringIndex.cc Mon Feb 13 15:35:14 2006
@@ -39,7 +39,8 @@
}
if (begin == -1 || strcmp(data(begin), str) != 0)
- throw NotFoundException(string("looking for the ID of string ") + str);
+ //throw NotFoundException(string("looking for the ID of string ") + str);
+ return -1;
else
return begin;
}
Modified: tagcoll/trunk/tagcoll/StringIndex.h
==============================================================================
--- tagcoll/trunk/tagcoll/StringIndex.h (original)
+++ tagcoll/trunk/tagcoll/StringIndex.h Mon Feb 13 15:35:14 2006
@@ -40,8 +40,8 @@
* [0-terminated string 1][0-terminated string 2][...]
* [number of items in the mapping]
*
- * This class tries to be a simple and fast component for building indexes, and
- * thus no bound checking is performed.
+ * The index of a string not present in the index is assumed to be -1
+ * The string corresponding to an invalid index is ""
*/
class StringIndex : public MMapIndex, public Converter<int, std::string>, public Converter<std::string, int>
{
@@ -55,7 +55,7 @@
virtual std::string operator()(const int& item) const { return data(item); }
virtual int operator()(const std::string& item) const { return data(item.c_str()); }
- const char* data(int val) const { return (val >= 0 && val < (signed)size()) ? m_buf + offset(val) : 0; }
+ const char* data(int val) const { return (val >= 0 && (unsigned)val < size()) ? m_buf + offset(val) : ""; }
int data(const char* str) const;
size_t size() const { return *(unsigned int*)m_buf / sizeof(int); }
};
More information about the Debtags-commits
mailing list