• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • TDevelop Interfaces Library
 

TDevelop Interfaces Library

  • lib
  • interfaces
hashedstring.h
1 /***************************************************************************
2  copyright : (C) 2006 by David Nolden
3  email : david.nolden.kdevelop@art-master.de
4 ***************************************************************************/
5 
6 /***************************************************************************
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  ***************************************************************************/
14 
15 #ifndef HASHED_STRING_H
16 #define HASHED_STRING_H
17 
18 #include<tqstring.h>
19 #include<tqdatastream.h>
20 #include<ksharedptr.h>
21 #include<set>
22 #include <ext/hash_map>
23 #include <string>
24 
26 class HashedString {
27  public:
28  HashedString() : m_hash( 0 ) {}
29 
30  HashedString( const TQString& str ) : m_str( str ) {
31  initHash();
32  }
33 
34  HashedString( const char* str ) : m_str( str ) {
35  initHash();
36  }
37 
38  inline size_t hash() const {
39  return m_hash;
40  }
41 
42  TQString str() const {
43  return m_str;
44  }
45 
46  bool operator == ( const HashedString& rhs ) const {
47  if ( m_hash != rhs.m_hash )
48  return false;
49  return m_str == rhs.m_str;
50  }
51 
53  bool operator < ( const HashedString& rhs ) const {
54  if ( m_hash < rhs.m_hash )
55  return true;
56  if ( m_hash == rhs.m_hash )
57  return m_str < rhs.m_str;
58  return false;
59  }
60 
61  static size_t hashString( const TQString& str );
62 
63  private:
64  void initHash();
65 
66  TQString m_str;
67  size_t m_hash;
68 
69  friend TQDataStream& operator << ( TQDataStream& stream, const HashedString& str );
70  friend TQDataStream& operator >> ( TQDataStream& stream, HashedString& str );
71 };
72 
73 TQDataStream& operator << ( TQDataStream& stream, const HashedString& str );
74 
75 TQDataStream& operator >> ( TQDataStream& stream, HashedString& str );
76 
77 class HashedStringSetData;
78 class HashedStringSetGroup;
79 
81 class HashedStringSet {
82  public:
83  HashedStringSet();
84 
85  ~HashedStringSet();
86 
88  HashedStringSet( const HashedString& file );
89 
90  HashedStringSet( const HashedStringSet& rhs );
91 
92  int size() const;
93 
94  HashedStringSet& operator = ( const HashedStringSet& rhs );
96  bool operator[] ( const HashedString& rhs ) const;
97 
98  void insert( const HashedString& str );
99 
100  HashedStringSet& operator +=( const HashedStringSet& );
101 
102  HashedStringSet& operator -=( const HashedStringSet& );
103 
106  bool operator <= ( const HashedStringSet& rhs ) const;
107 
108  bool operator == ( const HashedStringSet& rhs ) const;
109 
110  void read( TQDataStream& stream );
111  void write( TQDataStream& stream ) const;
112 
113  std::string print() const;
114 
115  size_t hash() const;
116  private:
117  friend class HashedStringSetGroup;
118  void makeDataPrivate();
119  TDESharedPtr<HashedStringSetData> m_data; //this implies some additional cost because TDEShared's destructor is virtual. Maybe change that by copying TDEShared without the virtual destructor.
120  friend HashedStringSet operator + ( const HashedStringSet& lhs, const HashedStringSet& rhs );
121 };
122 
123 HashedStringSet operator + ( const HashedStringSet& lhs, const HashedStringSet& rhs );
124 
125 namespace __gnu_cxx {
126 template<>
127 struct hash<HashedString> {
128  size_t operator () ( const HashedString& str ) const {
129  return str.hash();
130  }
131 };
132 }
133 
135 class HashedStringSetGroup {
136  public:
137  typedef std::set<size_t> ItemSet;
138  void addSet( size_t id, const HashedStringSet& set );
139  void enableSet( size_t id );
140  bool isDisabled( size_t id ) const;
141  void disableSet( size_t id );
142  void removeSet( size_t id );
143 
144  //Writes the ids of all registered and not disabled HashedStringSet's that are completely included in the given HashedStringSet efficiently)
145  void findGroups( HashedStringSet strings, ItemSet& target ) const;
146 
147  private:
148  typedef __gnu_cxx::hash_map<HashedString, ItemSet> GroupMap;
149  typedef __gnu_cxx::hash_map<size_t, size_t> SizeMap;
150  GroupMap m_map;
151  SizeMap m_sizeMap;
152  ItemSet m_disabled;
153  ItemSet m_global;
154 };
155 #endif
HashedString::operator<
bool operator<(const HashedString &rhs) const
Does not compare alphabetically, uses the hash-key for ordering.
Definition: hashedstring.h:53
__gnu_cxx
Definition: hashedstring.h:125
HashedString
A simple class that stores a string together with it&#39;s appropriate hash-key.
Definition: hashedstring.h:26
HashedStringSet
This is a reference-counting string-set optimized for fast lookup of hashed strings.
Definition: hashedstring.h:81
HashedStringSetGroup
Used to find all registered HashedStringSet&#39;s that contain all strings given to findGroups(..)
Definition: hashedstring.h:135

TDevelop Interfaces Library

Skip menu "TDevelop Interfaces Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

TDevelop Interfaces Library

Skip menu "TDevelop Interfaces Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for TDevelop Interfaces Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.