gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
hash.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 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 {
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
Definition: hash.H:22
void dump(void)
Definition: Array.H:82
int hashFunction(int input, int min)
Definition: hash.H:39
Definition: hash.H:36
unsigned int size
Definition: Array.H:26
Arrays< Array< HTYPE > > arrays
Definition: hash.H:37
int len(void)
Definition: Array.H:64
Arrays(unsigned int size)
Definition: hash.H:25
Definition: Array.H:24
Arrays(void)
Definition: hash.H:24
void hashSort(unsigned int size, int *data)
Definition: hash.H:44
gtkIOStream: /tmp/gtkiostream/include/mffm/possible.future.additions/hash/hash.H Source File
GTK+ IOStream  Beta