Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Data/ILProrityQueue.cs @ 12448

Last change on this file since 12448 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 4.9 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40#region LGPL License
41/*   
42    This file is part of ILNumerics.Net Core Module.
43
44    ILNumerics.Net Core Module is free software: you can redistribute it
45    and/or modify it under the terms of the GNU Lesser General Public
46    License as published by the Free Software Foundation, either version 3
47    of the License, or (at your option) any later version.
48
49    ILNumerics.Net Core Module is distributed in the hope that it will be useful,
50    but WITHOUT ANY WARRANTY; without even the implied warranty of
51    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
52    GNU Lesser General Public License for more details.
53
54    You should have received a copy of the GNU Lesser General Public License
55    along with ILNumerics.Net Core Module. 
56    If not, see <http://www.gnu.org/licenses/>.
57*/
58#endregion
59
60using System;
61using System.Collections.Generic;
62using System.Text;
63
64namespace ILNumerics.Data {
65    /// <summary>
66    /// experimental performant priority queue implementation (WORK IN PROGRESS!)
67    /// </summary>
68    /// <typeparam name="T">inner type for elements (arbitrary)</typeparam>
69    public class ILProrityQueue<T> : ILBinTree<T> where T:IComparable {
70        /// <summary>
71        /// add an element to the queue
72        /// </summary>
73        /// <param name="element"></param>
74        public void Add(T element) {
75            ILBinTreeNode<T> cur = null; // m_root;
76            while (cur != null) {
77               
78            }
79            m_count++;
80        }
81
82        private void createHeap() {
83           
84        }
85        private void heapify(ILBinTreeNode<T> top) {
86            System.Diagnostics.Debug.Assert(top != null && top.Data != null);
87            int res;
88            ILBinTreeNode<T> child;
89            if (top.LeftSon != null) {
90                System.Diagnostics.Debug.Assert(top.LeftSon.Data != null);
91                T ls = top.LeftSon.Data;
92                if (top.RightSon != null) {
93                    System.Diagnostics.Debug.Assert(top.RightSon.Data != null);
94                    T rs = top.RightSon.Data;
95                    if (ls.CompareTo(rs) > 0)
96                        child = top.LeftSon;
97                    else
98                        child = top.RightSon;
99                } else {
100                    child = top.LeftSon;
101                }
102            } else {
103                if (top.RightSon != null) {
104                    System.Diagnostics.Debug.Assert(top.RightSon.Data != null);
105                    child = top.RightSon;
106                } else {
107                    return;
108                }
109            }
110            // may exchange this data with largest node's value
111            if (child.m_data.CompareTo(top.m_data) > 0) {
112                T tmp = child.m_data;
113                child.m_data = top.m_data;
114                top.m_data = tmp;
115                heapify(child);
116            }   
117        }
118    }
119}
Note: See TracBrowser for help on using the repository browser.