diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-11-13 02:53:47 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-11-13 02:54:19 -0500 |
commit | 7956fd07ade66f4ca35cc65472ef2a026b67bdc8 (patch) | |
tree | ff1854c4360dbe837c827250db5fdebdf7531179 /src/mongo/util/string_map.h | |
parent | 88055d1a66ba7daefe681900a79cd9c01896304f (diff) | |
download | mongo-7956fd07ade66f4ca35cc65472ef2a026b67bdc8.tar.gz |
SERVER-7639 fast StringMap class, no std::string copies
Diffstat (limited to 'src/mongo/util/string_map.h')
-rw-r--r-- | src/mongo/util/string_map.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/mongo/util/string_map.h b/src/mongo/util/string_map.h new file mode 100644 index 00000000000..e2fd7e01bc7 --- /dev/null +++ b/src/mongo/util/string_map.h @@ -0,0 +1,52 @@ +// string_map.h + +/* Copyright 2012 10gen Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <string> +#include "mongo/util/unordered_fast_key_table.h" + +namespace mongo { + + struct StringMapDefaultHash { + size_t operator()( const char* k ) const; + }; + + struct StringMapDefaultEqual { + bool operator()( const char* a, const char* b ) const { + return strcmp( a,b ) == 0; + } + }; + + struct StringMapDefaultConvertor { + const char* operator()( const std::string& s ) const { + return s.c_str(); + } + }; + + template< typename V > + class StringMap : public UnorderedFastKeyTable< const char*, // K_L + std::string, // K_S + V, // V + StringMapDefaultHash, + StringMapDefaultEqual, + StringMapDefaultConvertor > { + }; +} + +#include "mongo/util/string_map_internal.h" + |