[llvm-commits] CVS: llvm/include/llvm/ADT/SmallPtrSet.h

Chris Lattner sabre at nondot.org
Fri Jan 26 23:25:07 PST 2007



Changes in directory llvm/include/llvm/ADT:

SmallPtrSet.h updated: 1.1 -> 1.2
---
Log message:

add some comments on the algorithm


---
Diffs of the changes:  (+20 -1)

 SmallPtrSet.h |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletion(-)


Index: llvm/include/llvm/ADT/SmallPtrSet.h
diff -u llvm/include/llvm/ADT/SmallPtrSet.h:1.1 llvm/include/llvm/ADT/SmallPtrSet.h:1.2
--- llvm/include/llvm/ADT/SmallPtrSet.h:1.1	Sat Jan 27 01:10:46 2007
+++ llvm/include/llvm/ADT/SmallPtrSet.h	Sat Jan 27 01:24:51 2007
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file defines the SmallPtrSet class.
+// This file defines the SmallPtrSet class.  See the doxygen comment for
+// SmallPtrSetImpl for more details on the algorithm used.
 //
 //===----------------------------------------------------------------------===//
 
@@ -19,6 +20,24 @@
 
 namespace llvm {
 
+/// SmallPtrSetImpl - This is the common code shared among all the
+/// SmallPtrSet<>'s, which is almost everything.  SmallPtrSet has two modes, one
+/// for small and one for large sets.
+///
+/// Small sets use an array of pointers allocated in the SmallPtrSet object,
+/// which is treated as a simple array of pointers.  When a pointer is added to
+/// the set, the array is scanned to see if the element already exists, if not
+/// the element is 'pushed back' onto the array.  If we run out of space in the
+/// array, we grow into the 'large set' case.  SmallSet should be used when the
+/// sets are often small.  In this case, no memory allocation is used, and only
+/// light-weight and cache-efficient scanning is used.
+///
+/// Large sets use a classic exponentially-probed hash table.  Empty buckets are
+/// represented with an illegal pointer value (-1) to allow null pointers to be
+/// inserted.  Tombstones are represented with another illegal pointer value
+/// (-2), to allow deletion.  The hash table is resized when the table is 3/4 or
+/// more.  When this happens, the table is doubled in size.
+///
 class SmallPtrSetImpl {
 protected:
   /// CurArray - This is the current set of buckets.  If it points to






More information about the llvm-commits mailing list