1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
35 #define AssertionOf(x) {if (!(x)) {std::cerr << "Assertion failed: " << #x << __FILE__ << __LINE__ << std::endl; exit(3); }}
38 #define stricmp strcasecmp
43 Heap::Heap(unsigned i_nWidth
)
44 : dpColumnsArray(new Column
[i_nWidth
]),
45 nColumnsArraySize(i_nWidth
),
46 nActiveColumn(nColumnsArraySize
-1)
48 for ( unsigned i
= 0; i
< nColumnsArraySize
; i
++)
50 dpColumnsArray
[i
] = 0;
56 for ( unsigned i
= 0; i
< nColumnsArraySize
; i
++)
58 HeapItem
* & rColumn
= dpColumnsArray
[i
];
59 for ( HeapItem
* pValue
= rColumn
; pValue
!= 0; pValue
= rColumn
)
61 rColumn
= rColumn
->Next();
66 delete [] dpColumnsArray
;
70 Heap::InsertValue( const char * i_sKey
,
71 const char * i_sValue
)
73 HeapItem
* pSearch1
= 0;
74 HeapItem
* pSearch2
= 0;
75 HeapItem
* pNew
= new HeapItem(i_sKey
, i_sValue
);
78 pSearch1
= ActiveColumn();
80 if ( pSearch1
!= 0 ? *pNew
< *pSearch1
: true )
82 pNew
->SetNext( pSearch1
);
83 ActiveColumn() = pNew
;
85 if ( pNew
->Next() != 0)
87 AssertionOf( *pNew
<= *pNew
->Next() );
96 pSearch1
= pSearch1
->Next();
98 if ( pSearch1
!= 0 ? *pNew
< *pSearch1
: true )
100 pNew
->SetNext( pSearch1
);
101 pSearch2
->SetNext(pNew
);
104 AssertionOf( *pSearch2
<= *pNew
);
105 if ( pNew
->Next() != 0)
107 AssertionOf( *pNew
<= *pNew
->Next() );
111 } while (pSearch2
->Next() != pNew
);
126 unsigned nRetColumn
= 0;
127 HeapItem
* ret
= dpColumnsArray
[0];
128 HeapItem
* pSearch
= 0;
130 for ( unsigned i
= 1; i
< nColumnsArraySize
; ++i
)
132 pSearch
= dpColumnsArray
[i
];
135 if ( ret
== 0 ? true : *pSearch
< *ret
)
145 dpColumnsArray
[nRetColumn
] = ret
->Next();
153 if (++nActiveColumn
>= nColumnsArraySize
)
159 HeapItem::HeapItem( const char * i_sKey
,
160 const char * i_sValue
)
167 HeapItem::~HeapItem()
172 HeapItem::operator<( const HeapItem
& i_rOther
) const
174 int ret
= stricmp(sKey
.str(), i_rOther
.sKey
.str());
176 ret
= strcmp(sKey
.str(), i_rOther
.sKey
.str());
178 ret
= stricmp(sValue
.str(), i_rOther
.sValue
.str());
180 ret
= strcmp(sValue
.str(), i_rOther
.sValue
.str());
185 HeapItem::Key() const
191 HeapItem::Next() const
197 HeapItem::SetNext( HeapItem
* i_pNext
)
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */