[llvm-commits] [llvm] r151110 - in /llvm/trunk: docs/ProgrammersManual.html include/llvm/ADT/SparseSet.h unittests/ADT/SparseSetTest.cpp unittests/CMakeLists.txt

Nick Lewycky nicholas at mxc.ca
Tue Feb 21 22:50:21 PST 2012


Jakob Stoklund Olesen wrote:
> Author: stoklund
> Date: Tue Feb 21 18:56:08 2012
> New Revision: 151110
>
> URL: http://llvm.org/viewvc/llvm-project?rev=151110&view=rev
> Log:
> Add a Briggs and Torczon sparse set implementation.
>
> For objects that can be identified by small unsigned keys, SparseSet
> provides constant time clear() and fast deterministic iteration. Insert,
> erase, and find operations are typically faster than hash tables.
>
> SparseSet is useful for keeping information about physical registers,
> virtual registers, or numbered basic blocks.

> Added: llvm/trunk/include/llvm/ADT/SparseSet.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SparseSet.h?rev=151110&view=auto
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/SparseSet.h (added)
> +++ llvm/trunk/include/llvm/ADT/SparseSet.h Tue Feb 21 18:56:08 2012
> @@ -0,0 +1,259 @@
> +//===--- llvm/ADT/SparseSet.h - Sparse set ----------------------*- C++ -*-===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file defines the SparseSet class derived from the version described in
> +// Briggs, Torczon, "An efficient representation for sparse sets", ACM Letters
> +// on Programming Languages and Systems, Volume 2 Issue 1-4, March–Dec.  1993.

Non-ASCII bytes between "March" and "Dec"?

> +// Single entry set tests
> +TEST(SparseSetTest, SingleEntrySet) {
> +  USet Set;
> +  Set.setUniverse(10);
> +  std::pair<USet::iterator, bool>  IP = Set.insert(5);
> +  EXPECT_TRUE(IP.second);
> +  EXPECT_TRUE(IP.first == Set.begin());
> +
> +  EXPECT_FALSE(Set.empty());
> +  EXPECT_FALSE(Set.begin() == Set.end());
> +  EXPECT_TRUE(Set.begin() + 1 == Set.end());
> +  EXPECT_EQ(1u, Set.size());
> +
> +  EXPECT_TRUE(Set.find(0) == Set.end());
> +  EXPECT_TRUE(Set.find(9) == Set.end());
> +
> +  EXPECT_FALSE(Set.count(0));
> +  EXPECT_TRUE(Set.count(5));
> +
> +  // Redundant insert.
> +  IP = Set.insert(5);
> +  EXPECT_FALSE(IP.second);
> +  EXPECT_TRUE(IP.first == Set.begin());
> +
> +  // Erase non-existant element.

"existent"

Nick



More information about the llvm-commits mailing list