GTK+ IOStream
Beta
<< GTK+ >> add C++ IOStream operators to GTK+. Now with extra abilities ... like network serialisation
Main Page
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
mffm
possible.future.additions
hash
hash.H
Go to the documentation of this file.
1
/* Copyright 2000-2012 Matt Flax <flatmax@flatmax.org>
2
This file is part of GTK+ IOStream class set
3
4
GTK+ IOStream is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
8
9
GTK+ IOStream is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You have received a copy of the GNU General Public License
15
along with GTK+ IOStream
16
*/
17
#ifndef HASH_H
18
#define HASH_H
19
#include "
Array.H
"
20
21
template
<
class
ATYPE>
22
class
Arrays
:
public
Array
<ATYPE>{
23
public
:
24
Arrays
(
void
) :
Array
<ATYPE>(){}
25
Arrays
(
unsigned
int
size
) :
Array
<ATYPE>(size){}
27
};
28
29
//ostream& operator<<(ostream& c, const Arrays<ATYPE>& array){
30
// for (int i=0;i<array.len();i++)
31
// c<<array[i]<<'\n';
32
// return c;
33
//}
34
35
template
<
class
HTYPE>
36
class
Hash
{
37
Arrays< Array<HTYPE>
>
arrays
;
38
39
int
hashFunction
(
int
input,
int
min){
//, int max){
40
//cout<<"input, min, index = "<<input<<", "<<min<<", "<<input-min<<endl;
41
return
input-min;
42
}
43
public
:
44
void
hashSort
(
unsigned
int
size,
int
*data){
45
// O(N) find min and max
46
int
min=RAND_MAX;
//, max=-1;
47
for
(
int
i=0;i<size;i++){
48
//if (data[i]>max) max=data[i];
49
if
(data[i]<min) min=data[i];
50
}
51
//cout<<"max="<<max<<endl;
52
cout<<
"min="
<<min<<endl;
53
54
// O(N) - use hash function to index the arrays
55
for
(
int
i=0;i<size;i++){
56
unsigned
int
hashIndex=
hashFunction
(data[i],min);
//,max);
57
//cout<<"hashIndex="<<hashIndex<<'\t';
58
//cout<<"array len="<<arrays[hashIndex].len()<<'\n';
59
arrays
[hashIndex][
arrays
[hashIndex].
len
()]=data[i];
60
}
61
62
for
(
int
i=0;i<
arrays
.
len
();i++){
63
if
(
arrays
[i].len()){
64
arrays
[i].
dump
();
65
cout<<endl;
66
}
67
}
68
}
69
};
70
#endif //HASH_H
Generated on Tue Jun 4 2013 11:03:27 for GTK+ IOStream by
1.8.3.1