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>
33 friend class BigPtrArray
;
37 BigPtrEntry() : pBlock(0), nOffset(0) {}
38 virtual ~BigPtrEntry() {}
40 inline sal_uLong
GetPos() const;
41 inline BigPtrArray
& GetArray() const;
43 typedef BigPtrEntry
* ElementPtr
;
45 // 1000 entries per Block = a bit less then 4K
48 // number of entries that may remain free during compression
49 // this value is for the worst case; because we defined MAXBLOCK with ca 25%
50 // overhead, 80% = 800 entries are enough
51 // if complete compression is desired, 100 has to be specified
52 #define COMPRESSLVL 80
54 struct BlockInfo
{ // block info:
55 BigPtrArray
* pBigArr
; ///< in this array the block is located
56 ElementPtr
* pData
; ///< data block
57 sal_uLong nStart
, nEnd
; ///< start- and end index
58 sal_uInt16 nElem
; ///< number of elements
61 class SW_DLLPUBLIC BigPtrArray
64 BlockInfo
** ppInf
; // block info
65 sal_uLong nSize
; ///< number of elements
66 sal_uInt16 nMaxBlock
; ///< current max. number of blocks
67 sal_uInt16 nBlock
; ///< number of blocks
69 sal_uInt16 nCur
; ///< last used block
71 sal_uInt16
Index2Block( sal_uLong
) const; ///< block search
72 BlockInfo
* InsBlock( sal_uInt16
); ///< insert block
73 void BlockDel( sal_uInt16
); ///< some blocks were deleted
74 void UpdIndex( sal_uInt16
); ///< recalculate indices
77 // the short parameter specifies in percent, how full the blocks should be
79 sal_uInt16
Compress( short = COMPRESSLVL
);
85 sal_uLong
Count() const { return nSize
; }
87 void Insert( const ElementPtr
& r
, sal_uLong pos
);
88 void Remove( sal_uLong pos
, sal_uLong n
= 1 );
89 void Move( sal_uLong from
, sal_uLong to
);
90 void Replace( sal_uLong pos
, const ElementPtr
& r
);
92 ElementPtr
operator[]( sal_uLong
) const;
95 inline sal_uLong
BigPtrEntry::GetPos() const
97 assert(this == pBlock
->pData
[ nOffset
]); // element not in the block
98 return pBlock
->nStart
+ nOffset
;
101 inline BigPtrArray
& BigPtrEntry::GetArray() const
103 return *pBlock
->pBigArr
;
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */