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 .
22 #include <sal/config.h>
26 #include <sal/types.h>
28 #include <store/types.h>
31 namespace rtl
{ template <class reference_type
> class Reference
; }
32 namespace store
{ struct PageData
; }
40 public store::OStoreObject
42 static size_t const theTableSize
= 32;
43 static_assert((theTableSize
& (theTableSize
-1)) == 0, "table size should be a power of 2");
45 Entry
** m_hash_table
;
46 Entry
* m_hash_table_0
[theTableSize
] = {};
49 size_t const m_page_shift
;
51 size_t m_hash_entries
; // total number of entries in table.
55 static int hash_Impl(sal_uInt32 a
, size_t s
, size_t q
, size_t m
)
57 return static_cast<int>(((a
+ (a
>> s
) + (a
>> (s
<< 1))) >> q
) & m
);
59 int hash_index_Impl (sal_uInt32 nOffset
)
61 return hash_Impl(nOffset
, m_hash_shift
, m_page_shift
, m_hash_size
- 1);
64 Entry
* lookup_Impl (Entry
* entry
, sal_uInt32 nOffset
);
65 void rescale_Impl (std::size_t new_size
);
68 explicit PageCache (sal_uInt16 nPageSize
);
70 PageCache(const PageCache
&) = delete;
71 PageCache
& operator=(const PageCache
&) = delete;
73 storeError
lookupPageAt (
74 std::shared_ptr
<PageData
> & rxPage
,
77 storeError
insertPageAt (
78 std::shared_ptr
<PageData
> const & rxPage
,
81 storeError
updatePageAt (
82 std::shared_ptr
<PageData
> const & rxPage
,
85 storeError
removePageAt (
89 virtual ~PageCache() override
;
92 storeError
PageCache_createInstance (
93 rtl::Reference
< store::PageCache
> & rxCache
,
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */