LibreOffice Module idl (master) 1
hash.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21// program-sensitive includes
22#include <hash.hxx>
23
24SvStringHashEntry * SvStringHashTable::Insert( const OString& rElement, sal_uInt32 * pInsertPos )
25{
26 auto it = maString2IntMap.find(rElement);
27 if (it != maString2IntMap.end()) {
28 *pInsertPos = it->second;
29 return maInt2EntryMap[*pInsertPos].get();
30 }
31 maString2IntMap[rElement] = mnNextId;
32 maInt2EntryMap[mnNextId] = std::make_unique<SvStringHashEntry>(rElement);
33 *pInsertPos = mnNextId;
34 mnNextId++;
35 return maInt2EntryMap[*pInsertPos].get();
36}
37
38bool SvStringHashTable::Test( const OString& rElement, sal_uInt32 * pInsertPos )
39{
40 auto it = maString2IntMap.find(rElement);
41 if (it != maString2IntMap.end()) {
42 *pInsertPos = it->second;
43 return true;
44 }
45 return false;
46}
47
48SvStringHashEntry * SvStringHashTable::Get( sal_uInt32 nInsertPos ) const
49{
50 auto it = maInt2EntryMap.find(nInsertPos);
51 return it->second.get();
52}
53
54OString SvStringHashTable::GetNearString( std::string_view rName ) const
55{
56 for( auto const & rPair : maInt2EntryMap )
57 {
58 SvStringHashEntry * pE = rPair.second.get();
59 if( pE->GetName().equalsIgnoreAsciiCase( rName ) && pE->GetName() != rName )
60 return pE->GetName();
61 }
62 return OString();
63}
64
65/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStringHashEntry * Get(sal_uInt32 nInsertPos) const
Definition: hash.cxx:48
std::unordered_map< sal_uInt32, std::unique_ptr< SvStringHashEntry > > maInt2EntryMap
Definition: hash.hxx:48
std::unordered_map< OString, sal_uInt32 > maString2IntMap
Definition: hash.hxx:49
SvStringHashEntry * Insert(OString const &rElement, sal_uInt32 *pInsertPos)
Definition: hash.cxx:24
OString GetNearString(std::string_view rName) const
Definition: hash.cxx:54
sal_uInt32 mnNextId
Definition: hash.hxx:50
bool Test(OString const &rElement, sal_uInt32 *pInsertPos)
Definition: hash.cxx:38
FormulaCommand pE