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 .
25 #include <tools/solar.h>
26 #include <osl/diagnose.h>
34 friend class BigPtrArray
;
38 virtual ~BigPtrEntry() {}
40 BigPtrEntry() : pBlock(0), nOffset(0) {}
42 inline sal_uLong
GetPos() const;
43 inline BigPtrArray
& GetArray() const;
45 typedef BigPtrEntry
* ElementPtr
;
48 typedef bool (*FnForEach
)( const ElementPtr
&, void* pArgs
);
50 // 1000 entries per Block = a bit less then 4K
54 // number of entries that may remain free during compression
55 // this value is for the worst case; because we defined MAXBLOCK with ca 25%
56 // overhead, 80% = 800 entries are enough
57 // if complete compression is desired, 100 has to be specified
58 #define COMPRESSLVL 80
60 struct BlockInfo
{ // block info:
61 BigPtrArray
* pBigArr
; ///< in this array the block is located
62 ElementPtr
* pData
; ///< data block
63 sal_uLong nStart
, nEnd
; ///< start- and end index
64 sal_uInt16 nElem
; ///< number of elements
67 class SW_DLLPUBLIC BigPtrArray
69 BlockInfo
** ppInf
; // block info
70 sal_uLong nSize
; ///< number of elements
71 sal_uInt16 nMaxBlock
; ///< current max. number of blocks
72 sal_uInt16 nBlock
; ///< number of blocks
74 sal_uInt16 nCur
; ///< last used block
76 sal_uInt16
Index2Block( sal_uLong
) const; ///< block search
77 BlockInfo
* InsBlock( sal_uInt16
); ///< insert block
78 void BlockDel( sal_uInt16
); ///< some blocks were deleted
79 void UpdIndex( sal_uInt16
); ///< recalculate indices
83 // the short parameter specifies in percent, how full the blocks should be
85 sal_uInt16
Compress( short = COMPRESSLVL
);
91 sal_uLong
Count() const { return nSize
; }
93 void Insert( const ElementPtr
& r
, sal_uLong pos
);
94 void Remove( sal_uLong pos
, sal_uLong n
= 1 );
95 void Move( sal_uLong from
, sal_uLong to
);
96 void Replace( sal_uLong pos
, const ElementPtr
& r
);
98 ElementPtr
operator[]( sal_uLong
) const;
99 void ForEach( FnForEach fn
, void* pArgs
= NULL
)
101 ForEach( 0, nSize
, fn
, pArgs
);
103 void ForEach( sal_uLong nStart
, sal_uLong nEnd
, FnForEach fn
, void* pArgs
= NULL
);
108 inline sal_uLong
BigPtrEntry::GetPos() const
110 assert(this == pBlock
->pData
[ nOffset
]); // element not in the block
111 return pBlock
->nStart
+ nOffset
;
114 inline BigPtrArray
& BigPtrEntry::GetArray() const
116 return *pBlock
->pBigArr
;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */