nss: upgrade to release 3.73
[LibreOffice.git] / store / source / storcach.hxx
blob7032ade7b2dd7b3997668917989c3a177b384980
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_STORE_SOURCE_STORCACH_HXX
21 #define INCLUDED_STORE_SOURCE_STORCACH_HXX
23 #include <sal/config.h>
25 #include <memory>
27 #include <sal/types.h>
29 #include <store/types.h>
30 #include "object.hxx"
32 namespace rtl { template <class reference_type> class Reference; }
33 namespace store { struct PageData; }
35 namespace store
38 struct Entry;
40 class PageCache :
41 public store::OStoreObject
43 // Representation
44 static size_t const theTableSize = 32;
45 static_assert((theTableSize & (theTableSize-1)) == 0, "table size should be a power of 2");
47 Entry ** m_hash_table;
48 Entry * m_hash_table_0[theTableSize] = {};
49 size_t m_hash_size;
50 size_t m_hash_shift;
51 size_t const m_page_shift;
53 size_t m_hash_entries; // total number of entries in table.
54 size_t m_nHit;
55 size_t m_nMissed;
57 static int hash_Impl(sal_uInt32 a, size_t s, size_t q, size_t m)
59 return static_cast<int>(((a + (a >> s) + (a >> (s << 1))) >> q) & m);
61 int hash_index_Impl (sal_uInt32 nOffset)
63 return hash_Impl(nOffset, m_hash_shift, m_page_shift, m_hash_size - 1);
66 Entry * lookup_Impl (Entry * entry, sal_uInt32 nOffset);
67 void rescale_Impl (std::size_t new_size);
69 public:
70 explicit PageCache (sal_uInt16 nPageSize);
72 PageCache(const PageCache&) = delete;
73 PageCache& operator=(const PageCache&) = delete;
75 /** load.
77 storeError lookupPageAt (
78 std::shared_ptr<PageData> & rxPage,
79 sal_uInt32 nOffset);
81 /** insert.
83 storeError insertPageAt (
84 std::shared_ptr<PageData> const & rxPage,
85 sal_uInt32 nOffset);
87 /** update, or insert.
89 storeError updatePageAt (
90 std::shared_ptr<PageData> const & rxPage,
91 sal_uInt32 nOffset);
93 /** remove (invalidate).
95 storeError removePageAt (
96 sal_uInt32 nOffset);
98 protected:
99 virtual ~PageCache() override;
102 storeError PageCache_createInstance (
103 rtl::Reference< store::PageCache > & rxCache,
104 sal_uInt16 nPageSize
107 } // namespace store
109 #endif // INCLUDED_STORE_SOURCE_STORCACH_HXX
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */