File indexing completed on 2024-11-17 04:55:18

0001 /*
0002     SPDX-License-Identifier: MPL-2.0
0003 */
0004 
0005 /* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license.
0006  * This Source Code Form is subject to the terms of the Mozilla Public
0007  * License, v. 2.0. If a copy of the MPL was not distributed with this
0008  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
0009 
0010 #include <iostream>
0011 #include "./hash_set.h"
0012 #include "./test/example_data.h"
0013 
0014 using std::cout;
0015 using std::endl;
0016 
0017 int main(int argc, char **argv) {
0018   // Bucket size is 256 and don't allow multiple items per item hash.
0019   HashSet<ExampleData> set(256, false);
0020   set.Add(ExampleData("test"));
0021 
0022   // Prints true
0023   cout << "test exists: " << (set.Exists(ExampleData("test"))
0024       ? "true" : "false") << endl;
0025   // Prints false
0026   cout << "test2 exists: " << (set.Exists(ExampleData("test2"))
0027       ? "true" : "false") << endl;
0028 
0029   uint32_t len;
0030   char * buffer = set.Serialize(&len);
0031   HashSet<ExampleData> set2(0, false);
0032   set2.Deserialize(buffer, len);
0033   // Prints true
0034   cout << "test exists: " << (set2.Exists(ExampleData("test"))
0035       ? "true" : "false") << endl;
0036   // Prints false
0037   cout << "test2 exists: " << (set2.Exists(ExampleData("test2"))
0038       ? "true" : "false") << endl;
0039 
0040   delete[] buffer;
0041   return 0;
0042 }