/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these librararies and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* * $XConsortium: sorter.cc /main/3 1996/06/11 17:20:47 cde-hal $ * * Copyright (c) 1993 HAL Computer Systems International, Ltd. * All rights reserved. Unpublished -- rights reserved under * the Copyright Laws of the United States. USE OF A COPYRIGHT * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION * OR DISCLOSURE. * * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE, * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS * INTERNATIONAL, LTD. * * RESTRICTED RIGHTS LEGEND * Use, duplication, or disclosure by the Government is subject * to the restrictions as set forth in subparagraph (c)(l)(ii) * of the Rights in Technical Data and Computer Software clause * at DFARS 252.227-7013. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * */ #include "hmphf/sorter.h" /*#define NUM_BUCKETS 10 */ #define NUM_BUCKETS 5000 sorter::sorter(char* key_file) : v_max_bucket_sz(0), v_no_unique_keys(0), v_unique_keys(0), b_convertor(NUM_BUCKETS, 128) { fstream in(key_file, ios::in); _init(in); } sorter::sorter(istream& in) : v_max_bucket_sz(0), v_no_unique_keys(0), v_unique_keys(0), b_convertor(NUM_BUCKETS, 128) { _init(in); } void sorter::_init(istream& in) { v_bucket_array = new bucketPtr[NUM_BUCKETS]; int i; for ( i=0; i add_key(key_buf, true); } v_max_bucket_sz = MAX(v_max_bucket_sz, k); in.getline(key_buf, LBUFSIZ); // skip the next info field } filter_by_hash(); assemble_unique_keys(); } sorter::~sorter() { int i; for ( i=0; i key_ptr; while ( lp ) { remove_keys(bkt, (char*)(lp -> void_ptr()), lp); lp = (slist_void_ptr_cell*)(lp -> v_succ); } } void sorter::remove_keys(bucketPtr bkt, char* key, slist_void_ptr_cell* lp) { //debug(cerr, key); slist_void_ptr_cell *llp = lp; while ( llp && llp -> v_succ ) { slist_void_ptr_cell *next_lp = (slist_void_ptr_cell*)llp -> v_succ; //debug(cerr, (char*)(next_lp -> void_ptr())); if ( strcmp( key, (char*)(next_lp -> void_ptr()) ) == 0 ) { //MESSAGE(cerr, "rmove key:"); //cerr << (char*)(next_lp -> void_ptr()) << "\n"; llp -> v_succ = next_lp -> v_succ; delete (char*)(next_lp -> void_ptr()); delete next_lp; bkt -> v_no_keys --; } else llp = (slist_void_ptr_cell*)(llp -> v_succ); } } // // // int n_chk = 0; // int n_idx = 0; // // slist_void_ptr_cell *lp = bkt -> key_ptr; // // while ( lp ) { // //// maintaint the order of key chains in v_check_table[]!!! // // char* key2 = ((char*)(lp -> void_ptr())); // // int hash = b_convertor.atoi( // key2, strlen(key2), // 1, 2*v_max_bucket_sz // ); // // if ( v_map_table[hash] != 0 ) { // // if ( v_map_table[hash] != (charPtr)1 ) { // v_check_table[n_chk++] = v_map_table[hash]; // v_map_table[hash] = (charPtr)1; // // set to occupied. so that the same // // key will be in the v_check_table once. // // assume 1 will never be the address // // of any keys. // } // // v_check_table[n_chk++] = key2; // // } else { // //v_map_table[hash] = ((Ostring*)(lp -> void_ptr())) -> get(); // v_map_table[hash] = ((char*)(lp -> void_ptr())); // } // // v_index_table[n_idx++] = hash; // remember the slot being set // // lp = (slist_void_ptr_cell*)(lp -> succ); // } ////debug(cerr, n_chk); // //// double check possiblly collided keys // int n_dup = 0; // for ( int u=0; u 0 ) { // slist_void_ptr_cell *lp = bkt -> key_ptr; // slist_void_ptr_cell *prev_lp = lp; // // int u = 0; // lp = (slist_void_ptr_cell*)(lp -> succ); // // while ( lp && u void_ptr())); //debug(cerr, int((char*)(lp -> void_ptr()))); //*/ // // // if ( v_dup_table[u] == ((char*)(lp -> void_ptr())) ) // { // //MESSAGE(cerr, "key removed:"); //debug(cerr, v_dup_table[u]); // // prev_lp -> succ = lp -> succ; // bkt -> v_no_keys --; // u++; // } else // prev_lp = lp; // // lp = (slist_void_ptr_cell*)(lp -> succ); // // } // } // //// clean v_map_table // for ( int k=0; k v_no_keys; } } v_unique_keys = new charPtr[v_no_unique_keys]; int j = 0; slist_void_ptr_cell *lp = 0; for ( i=0; i key_ptr; while ( lp ) { v_unique_keys[j++] = ((char*)(lp -> void_ptr())); lp -> set_vptr(0); lp = (slist_void_ptr_cell*)(lp -> v_succ); } } } ostream& operator<< (ostream& out, sorter& st) { debug(out, st.v_no_unique_keys); for ( int i=0; i