1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <sal/types.h>
29 #include <store/types.h>
32 namespace rtl
{ template <class reference_type
> class Reference
; }
33 namespace store
{ struct PageData
; }
41 public store::OStoreObject
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
] = {};
51 size_t const m_page_shift
;
53 size_t m_hash_entries
; // total number of entries in table.
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
);
70 explicit PageCache (sal_uInt16 nPageSize
);
72 PageCache(const PageCache
&) = delete;
73 PageCache
& operator=(const PageCache
&) = delete;
77 storeError
lookupPageAt (
78 std::shared_ptr
<PageData
> & rxPage
,
83 storeError
insertPageAt (
84 std::shared_ptr
<PageData
> const & rxPage
,
87 /** update, or insert.
89 storeError
updatePageAt (
90 std::shared_ptr
<PageData
> const & rxPage
,
93 /** remove (invalidate).
95 storeError
removePageAt (
99 virtual ~PageCache() override
;
102 storeError
PageCache_createInstance (
103 rtl::Reference
< store::PageCache
> & rxCache
,
109 #endif // INCLUDED_STORE_SOURCE_STORCACH_HXX
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */