LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringSet.h
Go to the documentation of this file.
1 //===--- StringSet.h - The LLVM Compiler Driver -----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // StringSet - A set-like wrapper for the StringMap.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ADT_STRINGSET_H
15 #define LLVM_ADT_STRINGSET_H
16 
17 #include "llvm/ADT/StringMap.h"
18 
19 namespace llvm {
20 
21  /// StringSet - A wrapper for StringMap that provides set-like functionality.
22  template <class AllocatorTy = llvm::MallocAllocator>
23  class StringSet : public llvm::StringMap<char, AllocatorTy> {
25  public:
26 
27  /// insert - Insert the specified key into the set. If the key already
28  /// exists in the set, return false and ignore the request, otherwise insert
29  /// it and return true.
30  bool insert(StringRef Key) {
31  // Get or create the map entry for the key; if it doesn't exist the value
32  // type will be default constructed which we use to detect insert.
33  //
34  // We use '+' as the sentinel value in the map.
35  assert(!Key.empty());
36  StringMapEntry<char> &Entry = this->GetOrCreateValue(Key);
37  if (Entry.getValue() == '+')
38  return false;
39  Entry.setValue('+');
40  return true;
41  }
42  };
43 }
44 
45 #endif // LLVM_ADT_STRINGSET_H
bool insert(StringRef Key)
Definition: StringSet.h:30
MapEntryTy & GetOrCreateValue(StringRef Key, InitTy Val)
Definition: StringMap.h:361
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:23
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110