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 #include <tools/debug.hxx>
21 #include <sal/log.hxx>
28 // creates the asymmetric difference with another bitset
30 IndexBitSet
& IndexBitSet::operator-=(sal_uInt16 nBit
)
32 sal_uInt16 nBlock
= nBit
/ 32;
33 sal_uInt32 nBitVal
= 1L << (nBit
% 32);
35 if ( nBlock
>= nBlocks
)
38 if ( (*(pBitmap
+nBlock
) & nBitVal
) )
40 *(pBitmap
+nBlock
) &= ~nBitVal
;
47 // unites with a single bit
49 IndexBitSet
& IndexBitSet::operator|=( sal_uInt16 nBit
)
51 sal_uInt16 nBlock
= nBit
/ 32;
52 sal_uInt32 nBitVal
= 1L << (nBit
% 32);
54 if ( nBlock
>= nBlocks
)
56 sal_uInt32
*pNewMap
= new sal_uInt32
[nBlock
+1];
57 memset( pNewMap
+ nBlocks
, 0, 4 * (nBlock
- nBlocks
+ 1) );
61 memcpy( pNewMap
, pBitmap
, 4 * nBlocks
);
68 if ( (*(pBitmap
+nBlock
) & nBitVal
) == 0 )
70 *(pBitmap
+nBlock
) |= nBitVal
;
78 // determines if the bit is set (may be the only one)
80 bool IndexBitSet::Contains( sal_uInt16 nBit
) const
82 sal_uInt16 nBlock
= nBit
/ 32;
83 sal_uInt32 nBitVal
= 1L << (nBit
% 32);
85 if ( nBlock
>= nBlocks
)
87 return ( nBitVal
& *(pBitmap
+nBlock
) ) == nBitVal
;
90 IndexBitSet::IndexBitSet()
97 IndexBitSet::~IndexBitSet()
102 sal_uInt16
IndexBitSet::GetFreeIndex()
104 for(int i
=0;i
<USHRT_MAX
;i
++)
110 SAL_WARN( "sfx", "IndexBitSet enthaelt mehr als USHRT_MAX Eintraege");
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */