ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / applications / test / Hashing / testHashing.C
blob87d3623306acafe1ac789528248e13060245da63
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 Application
25     testHashing
27 Description
29 \*---------------------------------------------------------------------------*/
31 #include "IOstreams.H"
32 #include "IOobject.H"
33 #include "IFstream.H"
35 #include "stringList.H"
36 #include "labelList.H"
37 #include "labelPair.H"
38 #include "edgeList.H"
39 #include "triFaceList.H"
41 #include "Hash.H"
43 using namespace Foam;
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 //  Main program:
48 int main(int argc, char *argv[])
50     IFstream is("hashingTests");
53     while (is.good())
54     {
55         const word listType(is);
57         Info<< endl;
58         IOobject::writeDivider(Info) << listType << endl;
60         if (listType == "stringList")
61         {
62             Info<< "contiguous = " << contiguous<string>() << endl << endl;
64             stringList lst(is);
66             forAll(lst, i)
67             {
68                 unsigned hash1 = string::hash()(lst[i]);
70                 Info<< hex << hash1 << ": " << lst[i] << endl;
71             }
73         }
74         else if (listType == "labelList")
75         {
76             Info<<"contiguous = " << contiguous<label>() << endl << endl;
78             labelList lst(is);
80             forAll(lst, i)
81             {
82                 // direct value
83                 unsigned hash1 = Hash<label>()(lst[i]);
85                 // hashed byte-wise
86                 unsigned hash2 = Hash<label>()(lst[i], 0);
88                 Info<< hex << hash1
89                     << " (seeded: " << hash2 << ")"
90                     << ": " << dec << lst[i] << endl;
91             }
93             if (contiguous<label>())
94             {
95                 unsigned hash3 = Hasher
96                 (
97                     lst.cdata(),
98                     lst.size() * sizeof(label)
99                 );
101                 Info<<"contiguous hashed value " << hex << hash3 << endl;
102             }
103         }
104         else if (listType == "labelListList")
105         {
106             List< List<label> > lst(is);
108             forAll(lst, i)
109             {
110                 unsigned hash1 = Hasher
111                 (
112                     lst[i].cdata(),
113                     lst[i].size() * sizeof(label)
114                 );
116                 Info<< hex << hash1
117                     << ": " << dec << lst[i] << endl;
118             }
120         }
121         else if (listType == "edgeList")
122         {
123             Info<<"contiguous = " << contiguous<edge>() << endl << endl;
125             edgeList lst(is);
127             forAll(lst, i)
128             {
129                 unsigned hash1 = Hash<edge>()(lst[i]);
131                 // as FixedList
132                 unsigned hash2 = labelPair::Hash<>()(lst[i]);
134                 Info<< hex << hash1 << " (as FixedList: " << hash2
135                     << "): " << dec << lst[i] << endl;
136             }
137         }
138         else if (listType == "triFaceList")
139         {
140             Info<<"contiguous = " << contiguous<triFace>() << endl << endl;
142             triFaceList lst(is);
144             forAll(lst, i)
145             {
146                 // direct value
147                 unsigned hash1 = Hash<triFace>()(lst[i]);
148                 unsigned hash2 = FixedList<label, 3>::Hash<>()(lst[i]);
150                 Info<< hex << hash1 << " (as FixedList: " << hash2
151                     << "): " << dec << lst[i] << endl;
152             }
153         }
154         else
155         {
156             Info<< "unknown type: " << listType << endl;
157         }
159     }
161     return 0;
165 // ************************************************************************* //