android: Update app-specific/MIME type icons
[LibreOffice.git] / store / source / storcach.hxx
blobb787248349acd6bbcb3371911132e356b96d0c02
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 #pragma once
22 #include <sal/config.h>
24 #include <memory>
26 #include <sal/types.h>
28 #include <store/types.h>
29 #include "object.hxx"
31 namespace rtl { template <class reference_type> class Reference; }
32 namespace store { struct PageData; }
34 namespace store
37 struct Entry;
39 class PageCache :
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] = {};
47 size_t m_hash_size;
48 size_t m_hash_shift;
49 size_t const m_page_shift;
51 size_t m_hash_entries; // total number of entries in table.
52 size_t m_nHit;
53 size_t m_nMissed;
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);
67 public:
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,
75 sal_uInt32 nOffset);
77 storeError insertPageAt (
78 std::shared_ptr<PageData> const & rxPage,
79 sal_uInt32 nOffset);
81 storeError updatePageAt (
82 std::shared_ptr<PageData> const & rxPage,
83 sal_uInt32 nOffset);
85 storeError removePageAt (
86 sal_uInt32 nOffset);
88 protected:
89 virtual ~PageCache() override;
92 storeError PageCache_createInstance (
93 rtl::Reference< store::PageCache > & rxCache,
94 sal_uInt16 nPageSize
97 } // namespace store
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */