1193323Sed//===--- StringSet.h - The LLVM Compiler Driver -----------------*- C++ -*-===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open
6193323Sed// Source License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed//  StringSet - A set-like wrapper for the StringMap.
11193323Sed//
12193323Sed//===----------------------------------------------------------------------===//
13193323Sed
14193323Sed#ifndef LLVM_ADT_STRINGSET_H
15193323Sed#define LLVM_ADT_STRINGSET_H
16193323Sed
17193323Sed#include "llvm/ADT/StringMap.h"
18193323Sed
19193323Sednamespace llvm {
20193323Sed
21249423Sdim  /// StringSet - A wrapper for StringMap that provides set-like functionality.
22193323Sed  template <class AllocatorTy = llvm::MallocAllocator>
23193323Sed  class StringSet : public llvm::StringMap<char, AllocatorTy> {
24193323Sed    typedef llvm::StringMap<char, AllocatorTy> base;
25193323Sed  public:
26249423Sdim
27249423Sdim    /// insert - Insert the specified key into the set.  If the key already
28249423Sdim    /// exists in the set, return false and ignore the request, otherwise insert
29249423Sdim    /// it and return true.
30249423Sdim    bool insert(StringRef Key) {
31249423Sdim      // Get or create the map entry for the key; if it doesn't exist the value
32249423Sdim      // type will be default constructed which we use to detect insert.
33249423Sdim      //
34249423Sdim      // We use '+' as the sentinel value in the map.
35249423Sdim      assert(!Key.empty());
36249423Sdim      StringMapEntry<char> &Entry = this->GetOrCreateValue(Key);
37249423Sdim      if (Entry.getValue() == '+')
38243830Sdim        return false;
39249423Sdim      Entry.setValue('+');
40243830Sdim      return true;
41193323Sed    }
42193323Sed  };
43193323Sed}
44193323Sed
45193323Sed#endif // LLVM_ADT_STRINGSET_H
46