summaryrefslogtreecommitdiff
path: root/data/apt7/hashtable.diff
blob: fe5c046c84e7065df3f5538398ff09e7550420e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
diff -ru apt-0.7.20.2/apt-pkg/tagfile.cc apt-0.7.20.2+iPhone/apt-pkg/tagfile.cc
--- apt-0.7.20.2/apt-pkg/tagfile.cc	2009-02-07 15:09:35.000000000 +0000
+++ apt-0.7.20.2+iPhone/apt-pkg/tagfile.cc	2009-04-19 02:42:49.000000000 +0000
@@ -220,7 +220,10 @@
       if (isspace(Stop[0]) == 0)
       {
 	 Indexes[TagCount++] = Stop - Section;
-	 AlphaIndexes[AlphaHash(Stop,End)] = TagCount;
+         unsigned long hash(AlphaHash(Stop, End));
+         while (AlphaIndexes[hash] != 0)
+            hash = (hash + 1) % (sizeof(AlphaIndexes) / sizeof(AlphaIndexes[0]));
+	 AlphaIndexes[hash] = TagCount;
       }
 
       Stop = (const char *)memchr(Stop,'\n',End - Stop);
@@ -258,14 +261,16 @@
 bool pkgTagSection::Find(const char *Tag,unsigned &Pos) const
 {
    unsigned int Length = strlen(Tag);
-   unsigned int I = AlphaIndexes[AlphaHash(Tag)];
-   if (I == 0)
-      return false;
-   I--;
+   unsigned int J = AlphaHash(Tag);
    
-   for (unsigned int Counter = 0; Counter != TagCount; Counter++, 
-	I = (I+1)%TagCount)
+   for (unsigned int Counter = 0; Counter != TagCount; Counter++,
+	J = (J+1)%(sizeof(AlphaIndexes)/sizeof(AlphaIndexes[0])))
    {
+      unsigned int I = AlphaIndexes[J];
+      if (I == 0)
+         return false;
+      I--;
+
       const char *St;
       St = Section + Indexes[I];
       if (strncasecmp(Tag,St,Length) != 0)
@@ -291,14 +296,16 @@
 		         const char *&End) const
 {
    unsigned int Length = strlen(Tag);
-   unsigned int I = AlphaIndexes[AlphaHash(Tag)];
-   if (I == 0)
-      return false;
-   I--;
+   unsigned int J = AlphaHash(Tag);
    
-   for (unsigned int Counter = 0; Counter != TagCount; Counter++, 
-	I = (I+1)%TagCount)
+   for (unsigned int Counter = 0; Counter != TagCount; Counter++,
+	J = (J+1)%(sizeof(AlphaIndexes)/sizeof(AlphaIndexes[0])))
    {
+      unsigned int I = AlphaIndexes[J];
+      if (I == 0)
+         return false;
+      I--;
+
       const char *St;
       St = Section + Indexes[I];
       if (strncasecmp(Tag,St,Length) != 0)