Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

  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. #ifndef LLVM_ADT_STRINGSET_H
  14. #define LLVM_ADT_STRINGSET_H
  15. #include "llvm/ADT/StringMap.h"
  16. namespace llvm {
  17. /// StringSet - A wrapper for StringMap that provides set-like functionality.
  18. template <class AllocatorTy = llvm::MallocAllocator>
  19. class StringSet : public llvm::StringMap<char, AllocatorTy> {
  20. typedef llvm::StringMap<char, AllocatorTy> base;
  21. public:
  22. /// insert - Insert the specified key into the set. If the key already
  23. /// exists in the set, return false and ignore the request, otherwise insert
  24. /// it and return true.
  25. bool insert(StringRef Key) {
  26. // Get or create the map entry for the key; if it doesn't exist the value
  27. // type will be default constructed which we use to detect insert.
  28. //
  29. // We use '+' as the sentinel value in the map.
  30. assert(!Key.empty());
  31. StringMapEntry<char> &Entry = this->GetOrCreateValue(Key);
  32. if (Entry.getValue() == '+')
  33. return false;
  34. Entry.setValue('+');
  35. return true;
  36. }
  37. };
  38. }
  39. #endif // LLVM_ADT_STRINGSET_H