Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SW_INC_BPARR_HXX
21 : #define INCLUDED_SW_INC_BPARR_HXX
22 :
23 : #include <assert.h>
24 :
25 : #include <tools/solar.h>
26 : #include <swdllapi.h>
27 :
28 : struct BlockInfo;
29 : class BigPtrArray;
30 :
31 0 : class BigPtrEntry
32 : {
33 : friend class BigPtrArray;
34 : BlockInfo* pBlock;
35 : sal_uInt16 nOffset;
36 : public:
37 258951 : BigPtrEntry() : pBlock(0), nOffset(0) {}
38 257917 : virtual ~BigPtrEntry() {}
39 :
40 : inline sal_uLong GetPos() const;
41 : inline BigPtrArray& GetArray() const;
42 : };
43 : typedef BigPtrEntry* ElementPtr;
44 :
45 : // 1000 entries per Block = a bit less then 4K
46 : #define MAXENTRY 1000
47 :
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
53 :
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
59 : };
60 :
61 : class SW_DLLPUBLIC BigPtrArray
62 : {
63 : protected:
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
68 : mutable
69 : sal_uInt16 nCur; ///< last used block
70 :
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
75 :
76 : // fill all blocks
77 : // the short parameter specifies in percent, how full the blocks should be
78 : // made
79 : sal_uInt16 Compress( short = COMPRESSLVL );
80 :
81 : public:
82 : BigPtrArray();
83 : ~BigPtrArray();
84 :
85 1164591 : sal_uLong Count() const { return nSize; }
86 :
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);
91 :
92 : ElementPtr operator[]( sal_uLong ) const;
93 : };
94 :
95 198077709 : inline sal_uLong BigPtrEntry::GetPos() const
96 : {
97 : assert(this == pBlock->pData[ nOffset ]); // element not in the block
98 198077709 : return pBlock->nStart + nOffset;
99 : }
100 :
101 311062388 : inline BigPtrArray& BigPtrEntry::GetArray() const
102 : {
103 311062388 : return *pBlock->pBigArr;
104 : }
105 :
106 : #endif
107 :
108 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|