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_SW_INC_BPARR_HXX
21 #define INCLUDED_SW_INC_BPARR_HXX
25 #include <tools/solar.h>
35 friend class BigPtrArray
;
39 BigPtrEntry() : m_pBlock(nullptr), m_nOffset(0) {}
40 BigPtrEntry(BigPtrEntry
const &) = default;
41 virtual ~BigPtrEntry() = default;
42 BigPtrEntry
& operator =(BigPtrEntry
const &) = default;
44 inline sal_Int32
GetPos() const;
45 inline BigPtrArray
& GetArray() const;
48 // 1000 entries per Block = a bit less than 4K
51 // number of entries that may remain free during compression
52 // this value is for the worst case; because we defined MAXBLOCK with ca 25%
53 // overhead, 80% = 800 entries are enough
54 // if complete compression is desired, 100 has to be specified
55 #define COMPRESSLVL 80
57 struct BlockInfo final
59 BigPtrArray
* pBigArr
; ///< in this array the block is located
60 sal_Int32 nStart
, nEnd
; ///< start- and end index
61 sal_uInt16 nElem
; ///< number of elements
62 std::array
<BigPtrEntry
*, MAXENTRY
>
63 mvData
; ///< data block
66 class SW_DLLPUBLIC BigPtrArray
69 std::unique_ptr
<BlockInfo
*[]>
70 m_ppInf
; ///< block info
71 sal_Int32 m_nSize
; ///< number of elements
72 sal_uInt16 m_nMaxBlock
; ///< current max. number of blocks
73 sal_uInt16 m_nBlock
; ///< number of blocks
75 sal_uInt16 m_nCur
; ///< last used block
77 sal_uInt16
Index2Block( sal_Int32
) const; ///< block search
78 BlockInfo
* InsBlock( sal_uInt16
); ///< insert block
79 void BlockDel( sal_uInt16
); ///< some blocks were deleted
80 void UpdIndex( sal_uInt16
); ///< recalculate indices
83 sal_uInt16
Compress();
89 sal_Int32
Count() const { return m_nSize
; }
91 void Insert( BigPtrEntry
* p
, sal_Int32 pos
);
92 void Remove( sal_Int32 pos
, sal_Int32 n
= 1 );
93 void Move( sal_Int32 from
, sal_Int32 to
);
94 void Replace( sal_Int32 pos
, BigPtrEntry
* p
);
96 BigPtrEntry
* operator[]( sal_Int32
) const;
99 inline sal_Int32
BigPtrEntry::GetPos() const
101 assert(this == m_pBlock
->mvData
[ m_nOffset
]); // element not in the block
102 return m_pBlock
->nStart
+ m_nOffset
;
105 inline BigPtrArray
& BigPtrEntry::GetArray() const
107 return *m_pBlock
->pBigArr
;
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */