DtMmdb: move to lib directory as a standalone library.
This commit is contained in:
9
cde/lib/DtMmdb/index/Makefile.am
Normal file
9
cde/lib/DtMmdb/index/Makefile.am
Normal file
@@ -0,0 +1,9 @@
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
noinst_LTLIBRARIES = libindex.la
|
||||
|
||||
libindex_la_CXXFLAGS = -DPORTABLE_DB -I..
|
||||
|
||||
libindex_la_SOURCES = btree_index.C dyn_disk_index.C dyn_index.C \
|
||||
dyn_memory_index.C fast_mphf.C hash.C index.C \
|
||||
inv_lists.C mphf_index.C
|
||||
93
cde/lib/DtMmdb/index/btree_index.C
Normal file
93
cde/lib/DtMmdb/index/btree_index.C
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: btree_index.cc /main/4 1996/06/11 17:21:02 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 "index/btree_index.h"
|
||||
|
||||
#ifdef C_API
|
||||
#define v_static_key (*v_static_key_ptr)
|
||||
#endif
|
||||
|
||||
|
||||
btree_index::btree_index() : dyn_index(BTREE_INDEX_CODE)
|
||||
{
|
||||
}
|
||||
|
||||
Boolean
|
||||
btree_index::init_data_member( inv_lists_handler* y, const char* btree_store )
|
||||
{
|
||||
v_inv_lists_hd = y;
|
||||
v_idx_agent_ptr = new btree(btree_store);
|
||||
|
||||
set_mode(HEALTH, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
btree_index::~btree_index()
|
||||
{
|
||||
delete v_idx_agent_ptr;
|
||||
}
|
||||
|
||||
size_t btree_index::handler_to_inv_idx(const handler& query)
|
||||
{
|
||||
get_key_string(query);
|
||||
|
||||
data_t k(v_static_key.get(), v_static_key.size());
|
||||
|
||||
if ( v_idx_agent_ptr -> member(k) == false )
|
||||
throw(stringException("first_of_invlist(): key is not in btree"));
|
||||
|
||||
return size_t(k.dt);
|
||||
}
|
||||
|
||||
|
||||
MMDB_BODIES(btree_index)
|
||||
HANDLER_BODIES(btree_index)
|
||||
76
cde/lib/DtMmdb/index/btree_index.h
Normal file
76
cde/lib/DtMmdb/index/btree_index.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: btree_index.h /main/5 1996/07/18 14:33:52 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _btree_index_h
|
||||
#define _btree_index_h 1
|
||||
|
||||
#include "index/dyn_index.h"
|
||||
#include "btree/mmdb_btree.h"
|
||||
|
||||
class btree_index : public dyn_index
|
||||
{
|
||||
|
||||
public:
|
||||
btree_index();
|
||||
virtual ~btree_index();
|
||||
|
||||
//init run time data members
|
||||
Boolean init_data_member( inv_lists_handler*, const char* btree_store );
|
||||
|
||||
size_t handler_to_inv_idx(const handler& query);
|
||||
|
||||
MMDB_SIGNATURES(btree_index);
|
||||
};
|
||||
|
||||
|
||||
HANDLER_SIGNATURES(btree_index)
|
||||
|
||||
#endif
|
||||
82
cde/lib/DtMmdb/index/dyn_disk_index.C
Normal file
82
cde/lib/DtMmdb/index/dyn_disk_index.C
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: dyn_disk_index.cc /main/4 1996/06/11 17:21:12 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 "index/dyn_disk_index.h"
|
||||
|
||||
|
||||
dyn_disk_index::dyn_disk_index() : dyn_index(DYN_DISK_INDEX_CODE)
|
||||
{
|
||||
}
|
||||
|
||||
dyn_disk_index::~dyn_disk_index()
|
||||
{
|
||||
delete v_idx_agent_ptr;
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_disk_index::init_data_member(inv_lists_handler* y, abs_storage* store)
|
||||
{
|
||||
v_inv_lists_hd = y;
|
||||
v_idx_agent_ptr = new disk_hash((page_storage*)store);
|
||||
|
||||
set_mode(HEALTH, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t dyn_disk_index::handler_to_inv_idx(const handler&)
|
||||
{
|
||||
throw(stringException("handler_to_int() not implemented"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
MMDB_BODIES(dyn_disk_index)
|
||||
HANDLER_BODIES(dyn_disk_index)
|
||||
75
cde/lib/DtMmdb/index/dyn_disk_index.h
Normal file
75
cde/lib/DtMmdb/index/dyn_disk_index.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: dyn_disk_index.h /main/5 1996/07/18 14:34:14 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _dyn_disk_index_h
|
||||
#define _dyn_disk_index_h 1
|
||||
|
||||
#include "index/dyn_index.h"
|
||||
#include "diskhash/disk_hash.h"
|
||||
|
||||
class dyn_disk_index : public dyn_index
|
||||
{
|
||||
|
||||
public:
|
||||
dyn_disk_index();
|
||||
virtual ~dyn_disk_index();
|
||||
|
||||
//init run time data components
|
||||
Boolean init_data_member( inv_lists_handler*, abs_storage* );
|
||||
|
||||
size_t handler_to_inv_idx(const handler&);
|
||||
|
||||
MMDB_SIGNATURES(dyn_disk_index);
|
||||
};
|
||||
|
||||
HANDLER_SIGNATURES(dyn_disk_index)
|
||||
|
||||
#endif
|
||||
299
cde/lib/DtMmdb/index/dyn_index.C
Normal file
299
cde/lib/DtMmdb/index/dyn_index.C
Normal file
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: dyn_index.cc /main/5 1996/07/18 14:34:38 drk $
|
||||
*
|
||||
* 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 "index/dyn_index.h"
|
||||
|
||||
#ifdef C_API
|
||||
#define v_static_key (*v_static_key_ptr)
|
||||
#endif
|
||||
|
||||
|
||||
dyn_index::dyn_index(c_code_t x) : c_index(x)
|
||||
{
|
||||
v_inv_lists_hd = 0;
|
||||
v_idx_agent_ptr = 0;
|
||||
}
|
||||
|
||||
|
||||
dyn_index::~dyn_index()
|
||||
{
|
||||
////////////////////////////////////////////////////////
|
||||
// Need not to delete index object handlers, as they
|
||||
// are handled by the object cache. qfc 6-17-93
|
||||
////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
data_t* dyn_index::hd_to_key(const handler& t)
|
||||
{
|
||||
get_key_string(t);
|
||||
/*
|
||||
MESSAGE(cerr, "dyn_index::hd_to_key():");
|
||||
if ( v_static_key.get() )
|
||||
debug(cerr, v_static_key.get());
|
||||
MESSAGE(cerr, "************");
|
||||
*/
|
||||
|
||||
return new data_t(v_static_key.get(), v_static_key.size());
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_index::insert_key_loc(const handler& t, const oid_t& id)
|
||||
{
|
||||
|
||||
//MESSAGE(cerr, "dyn_index::insert_key_loc()");
|
||||
//id.asciiOut(cerr); cerr << "\n";
|
||||
|
||||
|
||||
data_t* intKey = hd_to_key(t);
|
||||
|
||||
_insert_loc( *intKey, id );
|
||||
|
||||
delete intKey;
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_index::insert_key_loc(const oid_t& t, const oid_t& id)
|
||||
{
|
||||
data_t intKey(int(t.icode()), voidPtr(-1));
|
||||
return _insert_loc( intKey, id );
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_index::_insert_loc(data_t& intKey, const oid_t& id)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "in dyn_index insert()");
|
||||
debug(cerr, intKey);
|
||||
debug(cerr, id);
|
||||
debug(cerr, p);
|
||||
*/
|
||||
|
||||
if ( v_idx_agent_ptr -> member( intKey ) == true ) {
|
||||
|
||||
int hash = int(long((intKey.dt)));
|
||||
|
||||
//MESSAGE(cerr, "update inv list");
|
||||
//debug(cerr, hash);
|
||||
|
||||
/**************************/
|
||||
// just update the inv list
|
||||
/**************************/
|
||||
oid_list_handler* list_hd =
|
||||
(*v_inv_lists_hd) -> get_list(hash);
|
||||
|
||||
if ( list_hd == 0 )
|
||||
throw(stringException("NULL oidlist ptr"));
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "insert to list before");
|
||||
(*list_hd) -> asciiOut(cerr); cerr << "\n";
|
||||
*/
|
||||
|
||||
(*list_hd) -> insert_component(id);
|
||||
//list_hd -> commit();
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "insert to list after");
|
||||
(*list_hd) -> asciiOut(cerr); cerr << "\n";
|
||||
*/
|
||||
|
||||
delete list_hd;
|
||||
|
||||
|
||||
} else {
|
||||
//MESSAGE(cerr, "create inv list");
|
||||
|
||||
/**************************/
|
||||
// create a new inv list
|
||||
/**************************/
|
||||
oid_list list;
|
||||
list.insert_component(id);
|
||||
|
||||
(*v_inv_lists_hd) -> append_list(list);
|
||||
|
||||
intKey.dt = (voidPtr)(size_t)(*v_inv_lists_hd) -> count();
|
||||
//debug(cerr, int(intKey.dt));
|
||||
|
||||
v_idx_agent_ptr -> insert( intKey );
|
||||
|
||||
}
|
||||
/*
|
||||
MESSAGE(cerr, "dyn_index::_insert_loc(): ");
|
||||
v_idx_agent_ptr -> asciiOut(cerr);
|
||||
MESSAGE(cerr, "=========================");
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_index::remove_loc(handler& t, const oid_t& id)
|
||||
{
|
||||
data_t* intKey = hd_to_key(t);
|
||||
|
||||
if ( intKey == 0 )
|
||||
return false;
|
||||
else {
|
||||
Boolean ok = _remove_loc(*intKey, id);
|
||||
delete intKey;
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_index::remove_loc(const oid_t& t, const oid_t& id)
|
||||
{
|
||||
data_t intKey(int(t.icode()), voidPtr(-1));
|
||||
return _remove_loc(intKey, id);
|
||||
}
|
||||
|
||||
Boolean dyn_index::_remove_loc(data_t& intKey, const oid_t& id)
|
||||
{
|
||||
//MESSAGE(cerr, "_remove_loc()");
|
||||
|
||||
Boolean ok = v_idx_agent_ptr -> member( intKey );
|
||||
|
||||
if ( ok == false ) return true; // no key in the hash table.
|
||||
|
||||
//MESSAGE(cerr, "in hash table");
|
||||
int hash = int(long(intKey.dt));
|
||||
|
||||
oid_list_handler *list_hd =
|
||||
(*v_inv_lists_hd) -> get_list(hash);
|
||||
|
||||
if ( list_hd == 0 )
|
||||
throw(stringException("NULL oid list ptr"));
|
||||
|
||||
//MESSAGE(cerr, "remove_component():");
|
||||
(*list_hd) -> remove_component(id);
|
||||
|
||||
//list_hd -> commit();
|
||||
|
||||
//MESSAGE(cerr, "remove_component() done");
|
||||
|
||||
delete list_hd;
|
||||
|
||||
//MESSAGE(cerr, "_remove_loc() done");
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean dyn_index::update_streampos(handler& /* old_obj */,
|
||||
handler& /* new_obj */,
|
||||
mmdb_pos_t /* pos */
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
oid_list_handler* dyn_index::get_loc_list(const oid_t& id)
|
||||
{
|
||||
data_t intKey((int)id.icode());
|
||||
|
||||
if ( v_idx_agent_ptr -> member( intKey ) == true ) {
|
||||
|
||||
return (*v_inv_lists_hd) -> get_list(int(long(intKey.dt)));
|
||||
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
oid_list_handler* dyn_index::get_loc_list(const handler& t)
|
||||
{
|
||||
//MESSAGE(cerr, "dyn_index::get_loc_list()");
|
||||
//debug(cerr, (*v_inv_lists_hd) -> get_store() -> my_path());
|
||||
//debug(cerr, (*v_inv_lists_hd) -> get_store() -> my_name());
|
||||
|
||||
if ( OK() == false ) {
|
||||
MESSAGE(cerr,
|
||||
"dyn_index::get_loc_list(): bad index object status");
|
||||
return 0;
|
||||
}
|
||||
|
||||
data_t* intKey = 0;
|
||||
|
||||
if ( ( intKey = hd_to_key(t)) != 0 &&
|
||||
v_idx_agent_ptr -> member( *intKey ) == true
|
||||
) {
|
||||
//MESSAGE(cerr, "in hash table");
|
||||
|
||||
int p = int(long(intKey -> dt));
|
||||
//debug(cerr, p);
|
||||
delete intKey;
|
||||
//MESSAGE(cerr, "dyn_index::get_loc_list() done");
|
||||
|
||||
return (*v_inv_lists_hd) -> get_list(p);
|
||||
|
||||
} else {
|
||||
//MESSAGE(cerr, "not in hash table");
|
||||
delete intKey;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int dyn_index::invlist_length(handler& t)
|
||||
{
|
||||
oid_list_handler* locs = get_loc_list(t);
|
||||
|
||||
if ( locs == 0 )
|
||||
throw(stringException("NULL oid list ptr"));
|
||||
|
||||
return (*locs) -> count();
|
||||
}
|
||||
|
||||
io_status dyn_index::asciiOut(ostream& )
|
||||
{
|
||||
return done;
|
||||
}
|
||||
|
||||
101
cde/lib/DtMmdb/index/dyn_index.h
Normal file
101
cde/lib/DtMmdb/index/dyn_index.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: dyn_index.h /main/5 1996/07/18 14:35:04 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _dyn_index_h
|
||||
#define _dyn_index_h 1
|
||||
|
||||
#include "index/index.h"
|
||||
#include "dstr/index_agent.h"
|
||||
#include "index/inv_lists.h"
|
||||
|
||||
class dyn_index : public c_index
|
||||
{
|
||||
|
||||
public:
|
||||
dyn_index(c_code_t = DYN_INDEX_CODE);
|
||||
virtual ~dyn_index();
|
||||
|
||||
// insert index functions
|
||||
virtual Boolean insert_key_loc(const handler&, const oid_t&) ;
|
||||
virtual Boolean insert_key_loc(const oid_t&, const oid_t&) ;
|
||||
|
||||
// remove index functions
|
||||
virtual Boolean remove_loc(handler&, const oid_t&) ;
|
||||
virtual Boolean remove_loc(const oid_t&, const oid_t&);
|
||||
|
||||
// update index function
|
||||
virtual Boolean update_streampos(handler& old_obj,
|
||||
handler& new_obj,
|
||||
mmdb_pos_t pos
|
||||
) ;
|
||||
|
||||
// retrieval functions
|
||||
virtual oid_list_handler* get_loc_list(const oid_t&);
|
||||
virtual oid_list_handler* get_loc_list(const handler&);
|
||||
virtual int invlist_length(handler&) ;
|
||||
|
||||
// status inquiry functions
|
||||
virtual Boolean sorted() const { return false; };
|
||||
|
||||
// io function
|
||||
virtual io_status asciiOut(ostream&);
|
||||
|
||||
protected:
|
||||
Boolean _insert_loc(data_t& intKey, const oid_t& id);
|
||||
Boolean _remove_loc(data_t& intKey, const oid_t& id);
|
||||
data_t* hd_to_key(const handler& t);
|
||||
|
||||
protected:
|
||||
index_agent *v_idx_agent_ptr; // index agent (e.g. btree, hash) func
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
137
cde/lib/DtMmdb/index/dyn_memory_index.C
Normal file
137
cde/lib/DtMmdb/index/dyn_memory_index.C
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: dyn_memory_index.cc /main/4 1996/06/11 17:21:31 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 "index/dyn_memory_index.h"
|
||||
|
||||
|
||||
dyn_memory_index::dyn_memory_index() : dyn_index(DYN_MEMORY_INDEX_CODE)
|
||||
{
|
||||
}
|
||||
|
||||
Boolean
|
||||
dyn_memory_index::init_data_member(inv_lists_handler* y, abs_storage* store )
|
||||
{
|
||||
v_inv_lists_hd = y;
|
||||
storage_ptr = store;
|
||||
|
||||
if ( v_inv_lists_hd && (*v_inv_lists_hd) -> OK() ) {
|
||||
|
||||
v_idx_agent_ptr = new imp_die;
|
||||
|
||||
if ( exist_file(storage_ptr -> my_name(), storage_ptr -> my_path()) ==
|
||||
true ) {
|
||||
|
||||
fstream in(form("%s.%s", storage_ptr->my_path(), storage_ptr->my_name()), ios::in);
|
||||
v_idx_agent_ptr -> asciiIn(in);
|
||||
|
||||
}
|
||||
|
||||
set_mode(HEALTH, true);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
set_mode(HEALTH, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
dyn_memory_index::~dyn_memory_index()
|
||||
{
|
||||
//MESSAGE(cerr, "~dyn_memory_index() called");
|
||||
|
||||
if ( v_idx_agent_ptr ) {
|
||||
|
||||
/*
|
||||
char buf[PATHSIZ];
|
||||
for ( int i=0; i<PATHSIZ; buf[i++]=0 );
|
||||
|
||||
ostringstream oid_t_out(buf, PATHSIZ);
|
||||
my_oid().asciiOut(oid_t_out);
|
||||
*/
|
||||
|
||||
get_store();
|
||||
fstream out(
|
||||
form("%s.%s", storage_ptr->my_path(), storage_ptr->my_name()),
|
||||
ios::out
|
||||
);
|
||||
v_idx_agent_ptr -> asciiOut(out);
|
||||
}
|
||||
}
|
||||
|
||||
size_t dyn_memory_index::handler_to_inv_idx(const handler&)
|
||||
{
|
||||
throw(stringException(
|
||||
"dyn_memory_index::handler_to_int(): not implemented yet"
|
||||
)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Boolean dyn_memory_index::remove_loc(handler&, const oid_t&)
|
||||
{
|
||||
throw(stringException(
|
||||
"dyn_memory_index::remove_loc(): not implemented yet"
|
||||
)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean dyn_memory_index::remove_loc(const oid_t&, const oid_t&)
|
||||
{
|
||||
throw(stringException(
|
||||
"dyn_memory_index::remove_loc(): not implemented yet"
|
||||
)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
MMDB_BODIES(dyn_memory_index)
|
||||
HANDLER_BODIES(dyn_memory_index)
|
||||
80
cde/lib/DtMmdb/index/dyn_memory_index.h
Normal file
80
cde/lib/DtMmdb/index/dyn_memory_index.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: dyn_memory_index.h /main/5 1996/07/18 14:35:29 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _dyn_memory_index_h
|
||||
#define _dyn_memory_index_h 1
|
||||
|
||||
#include "index/dyn_index.h"
|
||||
|
||||
/**********************************************************/
|
||||
// A dynamic hash index class
|
||||
/**********************************************************/
|
||||
class dyn_memory_index : public dyn_index
|
||||
{
|
||||
|
||||
public:
|
||||
dyn_memory_index();
|
||||
virtual ~dyn_memory_index();
|
||||
|
||||
//init run time data components
|
||||
Boolean init_data_member( inv_lists_handler*, abs_storage* );
|
||||
|
||||
size_t handler_to_inv_idx(const handler&);
|
||||
|
||||
virtual Boolean remove_loc(handler&, const oid_t&);
|
||||
virtual Boolean remove_loc(const oid_t&, const oid_t&);
|
||||
|
||||
MMDB_SIGNATURES(dyn_memory_index);
|
||||
};
|
||||
|
||||
HANDLER_SIGNATURES(dyn_memory_index)
|
||||
|
||||
#endif
|
||||
537
cde/lib/DtMmdb/index/fast_mphf.C
Normal file
537
cde/lib/DtMmdb/index/fast_mphf.C
Normal file
@@ -0,0 +1,537 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: fast_mphf.cc /main/5 1996/07/18 14:35:57 drk $
|
||||
*
|
||||
* Copyright (c) 1992 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define NUM_BITS_INCREASES 5
|
||||
|
||||
#include "index/fast_mphf.h"
|
||||
|
||||
#ifdef C_API
|
||||
tbl_cache *fast_mphf::v_tbl_cache_ptr = 0;
|
||||
#define v_tbl_cache (*v_tbl_cache_ptr)
|
||||
#else
|
||||
tbl_cache fast_mphf::v_tbl_cache;
|
||||
#endif
|
||||
|
||||
tbl_record::~tbl_record()
|
||||
{
|
||||
delete v_tbl0;
|
||||
delete v_tbl1;
|
||||
}
|
||||
|
||||
tbl_cache::tbl_cache() : f_array(10)
|
||||
{
|
||||
}
|
||||
|
||||
tbl_cache::~tbl_cache()
|
||||
{
|
||||
for ( int v=0; v<f_array.no_elmts(); v++ ) {
|
||||
delete (tbl_record*)f_array[v];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void tbl_cache::init_table(int hash_tbl_sz, int seed, atoi_pearson*& t1, atoi_pearson*& t2)
|
||||
{
|
||||
int x = f_array.no_elmts();
|
||||
tbl_record *y = 0;
|
||||
|
||||
for ( int v=0; v<x; v++ ) {
|
||||
y = (tbl_record*)f_array[v];
|
||||
|
||||
if ( y -> v_tbl0 != 0 && y -> v_seed == seed )
|
||||
{
|
||||
|
||||
t1 = y -> v_tbl0;
|
||||
t2 = y -> v_tbl1;
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "USE cached TABLE!");
|
||||
debug(cerr, int(v_tbl0));
|
||||
debug(cerr, int(v_tbl1));
|
||||
*/
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
pm_random z(seed);
|
||||
t1 = new atoi_pearson(hash_tbl_sz, 128, z);
|
||||
t2 = new atoi_pearson(hash_tbl_sz, 128, z);
|
||||
|
||||
y = new tbl_record(seed, t1, t2);
|
||||
f_array.insert(y, x);
|
||||
f_array.reset_elmts(x+1);
|
||||
}
|
||||
|
||||
fast_mphf::fast_mphf(c_code_t c_cd): long_pstring(c_cd),
|
||||
v_long_string_core_indexed(false),
|
||||
v_no_ps(0), v_p1(0), v_p2(0),
|
||||
r(0), v_seed(0), t(0)
|
||||
{
|
||||
#ifdef C_API
|
||||
if ( v_tbl_cache_ptr == 0 ) {
|
||||
v_tbl_cache_ptr = new tbl_cache;
|
||||
}
|
||||
#endif
|
||||
|
||||
v_tbl0 = 0;
|
||||
v_tbl1 = 0;
|
||||
}
|
||||
|
||||
void fast_mphf::init_persistent_info(persistent_info* x)
|
||||
{
|
||||
long_pstring::init_persistent_info(x);
|
||||
if ( get_mode(OLD_OBJECT) == false ) {
|
||||
v_hash_tbl_sz = 0;
|
||||
v_no_ps = 0;
|
||||
v_p1 = 0;
|
||||
v_p2 = 0;
|
||||
r = 0;
|
||||
v_seed = 0;
|
||||
t = 0;
|
||||
ihash::init_data_member();
|
||||
}
|
||||
}
|
||||
|
||||
fast_mphf::~fast_mphf()
|
||||
{
|
||||
/*
|
||||
delete v_tbl0;
|
||||
delete v_tbl1;
|
||||
|
||||
#ifdef C_API
|
||||
if ( v_tbl_cache_ptr ) {
|
||||
for (int i=0; i<10; i++ )
|
||||
delete v_tbl_cache_ptr[i];
|
||||
delete v_tbl_cache_ptr;
|
||||
v_tbl_cache_ptr = 0;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
io_status fast_mphf::asciiIn(istream& in)
|
||||
{
|
||||
in >> v_hash_tbl_sz;
|
||||
in >> v_no_ps;
|
||||
in >> v_p1;
|
||||
in >> v_p2;
|
||||
in >> r;
|
||||
in >> v_seed;
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "in fast_mphf::asciiIn()");
|
||||
debug(cerr, my_oid());
|
||||
debug(cerr, v_hash_tbl_sz);
|
||||
debug(cerr, v_no_ps);
|
||||
debug(cerr, v_p1);
|
||||
debug(cerr, v_p2);
|
||||
debug(cerr, r);
|
||||
debug(cerr, v_seed);
|
||||
*/
|
||||
|
||||
v_key_set_sz = v_hash_tbl_sz ;
|
||||
|
||||
in.get(); // skip the '\n' after seed
|
||||
|
||||
long_pstring::asciiIn(in);
|
||||
|
||||
if ( v_key_set_sz > 0 ) {
|
||||
t = (int)(flog2(v_key_set_sz)) + 1; // bits of each g value.
|
||||
if ( floor(flog2(v_key_set_sz)) < flog2(v_key_set_sz) )
|
||||
t++;
|
||||
|
||||
//MESSAGE(cerr, "compacted array:");
|
||||
//debug(cerr, long_pstring::size());
|
||||
|
||||
//for (int z=0; z<long_pstring::size()/4; z++) {
|
||||
// cerr << ((unsigned*)long_pstring::get())[z] << " ";
|
||||
//}
|
||||
//cerr << "\n";
|
||||
|
||||
|
||||
v_hash_func_sz = v_no_ps*sizeof(unsigned)+128*2+6*sizeof(int);
|
||||
|
||||
init_map_tbls();
|
||||
|
||||
} else {
|
||||
v_hash_func_sz = 0;
|
||||
t = 0;
|
||||
}
|
||||
|
||||
set_mode(UPDATE, true);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
Boolean fast_mphf::init_map_tbls()
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "in fast_mphf::init_map_tbls()");
|
||||
debug(cerr, (void*)this);
|
||||
debug(cerr, my_oid());
|
||||
debug(cerr, v_key_set_sz);
|
||||
debug(cerr, v_hash_tbl_sz);
|
||||
debug(cerr, int(this));
|
||||
debug(cerr, v_no_ps);
|
||||
debug(cerr, v_p1);
|
||||
debug(cerr, v_p2);
|
||||
debug(cerr, r);
|
||||
debug(cerr, v_seed);
|
||||
debug(cerr, t);
|
||||
//debug(cerr, (void*)&v_tbl_cache);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
if ( v_key_set_sz > 0 ) {
|
||||
v_tbl_cache.init_table(v_hash_tbl_sz, v_seed, v_tbl0, v_tbl1);
|
||||
}
|
||||
|
||||
//long_pstring::init_run_data();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int fast_mphf::hashTo(const key_type& k)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if ( v_long_string_core_indexed == false ) {
|
||||
v_long_string_core_indexed = true;
|
||||
}
|
||||
/*
|
||||
cerr << "\n";
|
||||
MESSAGE(cerr, "fast_mphf:: hashTO()");
|
||||
debug(cerr, k);
|
||||
*/
|
||||
|
||||
|
||||
if ( v_hash_tbl_sz == 0 ) {
|
||||
throw(stringException("hash table empty"));
|
||||
}
|
||||
|
||||
i = v_tbl0 -> atoi(k.get(), k.size(), r, v_key_set_sz); // for halmphf
|
||||
|
||||
|
||||
if ( i < v_p1 ) {
|
||||
i %= v_p2;
|
||||
} else {
|
||||
i %= v_no_ps - v_p2;
|
||||
i += v_p2;
|
||||
}
|
||||
|
||||
int gv, c_bit;
|
||||
gValue(i, gv, c_bit);
|
||||
|
||||
|
||||
|
||||
//i = v_tbl1 -> atoi(k, c_bit+r+1) + gv;
|
||||
//debug(cerr, c_bit+r);
|
||||
|
||||
i = v_tbl1 -> atoi(k.get(), k.size(), c_bit+r+1, v_hash_tbl_sz) + gv; // for halmphf
|
||||
|
||||
|
||||
return i % v_hash_tbl_sz;
|
||||
}
|
||||
|
||||
int fast_mphf::gValue(int i, int& gvalue, int& ctl_bit)
|
||||
{
|
||||
if ( !INRANGE(i, 0, (int) v_no_ps-1) ) {
|
||||
throw(boundaryException(0, v_no_ps-1, i));
|
||||
}
|
||||
|
||||
int a, b;
|
||||
unsigned un_compacted, un_compacted1;
|
||||
|
||||
a = b = t * i ;
|
||||
a /= BITS_IN(unsigned);
|
||||
b %= BITS_IN(unsigned);
|
||||
|
||||
unsigned value_at_a, value_at_a_plus;
|
||||
/*
|
||||
debug(cerr, a);
|
||||
debug(cerr, b);
|
||||
debug(cerr, t);
|
||||
*/
|
||||
|
||||
char x_buf[10];
|
||||
|
||||
long_pstring::extract(a*sizeof(a), (a+1)*sizeof(a), x_buf);
|
||||
|
||||
memcpy((char*)&value_at_a, x_buf, sizeof(value_at_a));
|
||||
|
||||
|
||||
//cerr << "Extract: at " << a << "; the int =" << value_at_a << endl;
|
||||
#ifdef PORTABLE_DB
|
||||
if ( swap_order() == true )
|
||||
ORDER_SWAP_UINT(value_at_a);
|
||||
#endif
|
||||
//cerr << "after swap " << a << "; the int =" << value_at_a << endl;
|
||||
|
||||
//debug(cerr, hex(value_at_a));
|
||||
|
||||
|
||||
if ( BITS_IN(unsigned) - b >= t ) {
|
||||
|
||||
un_compacted = getbits(value_at_a, BITS_IN(unsigned) - b, t);
|
||||
|
||||
} else {
|
||||
|
||||
long_pstring::extract((a+1)*sizeof(a), (a+2)*sizeof(a), x_buf);
|
||||
|
||||
memcpy((char*)&value_at_a_plus, x_buf, sizeof(value_at_a_plus));
|
||||
|
||||
//cerr << "Extract+1: at " << (a+1) << "; the int =" << value_at_a_plus << endl;
|
||||
#ifdef PORTABLE_DB
|
||||
if ( swap_order() == true )
|
||||
ORDER_SWAP_UINT(value_at_a_plus);
|
||||
#endif
|
||||
//cerr << "after swap " << (a+1) << "; the int =" << value_at_a_plus << endl;
|
||||
|
||||
//debug(cerr, hex(value_at_a_plus));
|
||||
|
||||
un_compacted1 =
|
||||
getbits(value_at_a, BITS_IN(unsigned) - b, BITS_IN(unsigned) - b);
|
||||
un_compacted =
|
||||
getbits(value_at_a_plus, BITS_IN(unsigned), t - BITS_IN(unsigned) + b);
|
||||
un_compacted1 <<= ( t - BITS_IN(unsigned) + b);
|
||||
un_compacted |= un_compacted1;
|
||||
}
|
||||
//debug(cerr, hex(un_compacted));
|
||||
|
||||
ctl_bit = un_compacted & (unsigned)1;
|
||||
gvalue = un_compacted >> 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Boolean fast_mphf::build(const char *from)
|
||||
{
|
||||
fstream in(from, ios::in);
|
||||
return build(in);
|
||||
}
|
||||
|
||||
|
||||
Boolean fast_mphf::build(istream& in)
|
||||
{
|
||||
int ok = -1;
|
||||
|
||||
sorter stor(in);
|
||||
|
||||
params pms;
|
||||
|
||||
pms.v_n = stor.no_unique_keys();
|
||||
|
||||
pms.select_value();
|
||||
|
||||
buffer mphf_spec(LBUFSIZ);
|
||||
//buffer& mphf_spec = get_store() -> aux_buf();
|
||||
mphf_spec.set_swap_order(swap_order());
|
||||
|
||||
int i=0;
|
||||
while ( i<NUM_BITS_INCREASES && ok != 0 ) {
|
||||
|
||||
ok = compute_a_mphf(stor.unique_keys(), pms, mphf_spec);
|
||||
|
||||
switch (ok) {
|
||||
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
pms.re_select_value();
|
||||
break;
|
||||
|
||||
case -1:
|
||||
throw(stringException("finding a mphf failed"));
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if ( ok != 0 ) {
|
||||
set_mode(HEALTH, false);
|
||||
throw(stringException("finding a mphf failed"));
|
||||
}
|
||||
|
||||
stringstream strin;
|
||||
|
||||
if ( !strin ) {
|
||||
throw(streamException(strin.rdstate()));
|
||||
}
|
||||
else {
|
||||
strin.write(mphf_spec.get_base(), mphf_spec.content_sz());
|
||||
}
|
||||
|
||||
asciiIn(strin);
|
||||
|
||||
set_mode(HEALTH, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
fast_mphf::print_mapping(const char *key_file, int option)
|
||||
{
|
||||
//debug(cerr, option);
|
||||
MESSAGE(cerr, "print_mapping()");
|
||||
|
||||
char string[LBUFSIZ];
|
||||
fstream in(key_file, ios::in);
|
||||
|
||||
if ( !in ) {
|
||||
throw(streamException(in.rdstate()));
|
||||
}
|
||||
|
||||
char *hash_table = new char[v_hash_tbl_sz];
|
||||
for (unsigned int i = 0; i < v_hash_tbl_sz; hash_table[i++] = 0 );
|
||||
|
||||
ostring lbuf(LBUFSIZ);
|
||||
|
||||
|
||||
while ( in.getline(string, LBUFSIZ, '\n') ) {
|
||||
|
||||
// string[strlen(string)-1] = '\0';
|
||||
|
||||
//debug(cerr, string);
|
||||
//debug(cerr, strlen(string));
|
||||
|
||||
lbuf.reset();
|
||||
lbuf.set(string, strlen(string));
|
||||
|
||||
int hash = hashTo(lbuf) ;
|
||||
|
||||
if ( option == 1 ) {
|
||||
cout << " string = " << string;
|
||||
cout << ", hash = " << hash << "\n";
|
||||
}
|
||||
|
||||
if ( hash_table[hash] == 1 )
|
||||
MESSAGE(cerr, "mapping_print(): panic: mphf hash collision");
|
||||
else
|
||||
hash_table[hash] = 1;
|
||||
|
||||
in.getline(string, LBUFSIZ, '\n');
|
||||
}
|
||||
|
||||
MESSAGE(cerr, "print_mapping() done");
|
||||
}
|
||||
|
||||
void fast_mphf::print_tbls(ostream& out)
|
||||
{
|
||||
debug(out, *v_tbl0);
|
||||
debug(out, *v_tbl1);
|
||||
}
|
||||
|
||||
void fast_mphf::print_gvalues(ostream& out)
|
||||
{
|
||||
int gv, cbit;
|
||||
for (unsigned int i = 0; i<v_no_ps; i++ ) {
|
||||
out << i;
|
||||
gValue(i, gv, cbit);
|
||||
out << " " << gv << " " << cbit << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
int fast_mphf::print_bits(unsigned x, ostream& out)
|
||||
{
|
||||
for ( unsigned int i=0; i<8*sizeof(unsigned); i++ ) {
|
||||
if ( BIT_TEST(x, 0x80000000) )
|
||||
out << "1";
|
||||
else
|
||||
out << "0";
|
||||
x = x << 1;
|
||||
}
|
||||
out << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int fast_mphf::cdr_sizeof()
|
||||
{
|
||||
return long_pstring::cdr_sizeof() + ihash::cdr_sizeof() +
|
||||
6*sizeof(unsigned int);
|
||||
}
|
||||
|
||||
io_status fast_mphf::cdrOut(buffer& buf)
|
||||
{
|
||||
long_pstring::cdrOut(buf);
|
||||
ihash::cdrOut(buf);
|
||||
|
||||
buf.put(v_no_ps);
|
||||
buf.put(v_p1);
|
||||
buf.put(v_p2);
|
||||
buf.put(r);
|
||||
buf.put(v_seed);
|
||||
buf.put(t);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
io_status fast_mphf::cdrIn(buffer& buf)
|
||||
{
|
||||
long_pstring::cdrIn(buf);
|
||||
ihash::cdrIn(buf);
|
||||
|
||||
buf.get(v_no_ps);
|
||||
buf.get(v_p1);
|
||||
buf.get(v_p2);
|
||||
buf.get(r);
|
||||
buf.get(v_seed);
|
||||
buf.get(t);
|
||||
|
||||
init_map_tbls();
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MMDB_BODIES(fast_mphf)
|
||||
HANDLER_BODIES(fast_mphf)
|
||||
174
cde/lib/DtMmdb/index/fast_mphf.h
Normal file
174
cde/lib/DtMmdb/index/fast_mphf.h
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: fast_mphf.h /main/5 1996/07/18 14:36:28 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _fast_mphf_h
|
||||
#define _fast_mphf_h 1
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include "index/hash.h"
|
||||
#include "utility/atoi_pearson.h"
|
||||
#include "object/long_pstring.h"
|
||||
#include "utility/xtime.h"
|
||||
#include "hmphf/mphf_funcs.h"
|
||||
#include "hmphf/sorter.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// A fast MPHF contruct method proposed by Chen Qi Fan in 4/91.
|
||||
// Usually it will compute MPHFs using 2-3 bits/key.
|
||||
// Random number table size is reduced to 128 chars.
|
||||
// Computation is fast due to the pattern matching
|
||||
// used in the searching stage.
|
||||
//
|
||||
// Reference: VaTech Technical Report TR92-2, SIGIR92 paper.
|
||||
//
|
||||
// Modification:
|
||||
// convert to mmdb version (task started on 9-15-92)
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
class tbl_record
|
||||
{
|
||||
|
||||
public:
|
||||
int v_seed;
|
||||
atoi_pearson* v_tbl0;
|
||||
atoi_pearson* v_tbl1;
|
||||
|
||||
public:
|
||||
tbl_record(int sd = 0, atoi_pearson* t1 =0, atoi_pearson* t2 =0) :
|
||||
v_seed(sd), v_tbl0(t1), v_tbl1(t2) {};
|
||||
~tbl_record();
|
||||
};
|
||||
|
||||
class tbl_cache
|
||||
{
|
||||
protected:
|
||||
void_ptr_array f_array;
|
||||
|
||||
public:
|
||||
|
||||
tbl_cache();
|
||||
~tbl_cache();
|
||||
|
||||
void init_table(int hash_table_sz, int seed, atoi_pearson*&, atoi_pearson*&);
|
||||
|
||||
friend class fast_mphf;
|
||||
};
|
||||
|
||||
class fast_mphf : public long_pstring, public ihash
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
fast_mphf(c_code_t = FAST_MPHF_CODE);
|
||||
virtual ~fast_mphf();
|
||||
|
||||
MMDB_SIGNATURES(fast_mphf);
|
||||
|
||||
void init_persistent_info(persistent_info*);
|
||||
|
||||
|
||||
// init the two ascii->integer map tables
|
||||
Boolean init_map_tbls();
|
||||
|
||||
// load the MPHF from files
|
||||
using pstring::asciiIn;
|
||||
virtual io_status asciiIn(istream&);
|
||||
|
||||
// compute a hash value for a key.
|
||||
virtual int hashTo(const key_type&);
|
||||
|
||||
// compute a MPHF
|
||||
virtual Boolean build(const char* data_path);
|
||||
virtual Boolean build(istream& data_stream);
|
||||
|
||||
// show the mapping from keys to hash values and verify the mphf.
|
||||
// option = 0: no print, only check;
|
||||
// option = 1: print and check.
|
||||
void print_mapping( const char*key_file, int option = 0) ;
|
||||
|
||||
void print_gvalues(ostream&out = cerr) ;
|
||||
|
||||
virtual int cdr_sizeof();
|
||||
virtual io_status cdrOut(buffer&);
|
||||
virtual io_status cdrIn(buffer&);
|
||||
|
||||
protected:
|
||||
|
||||
// return the ith g value from the g array (in packed form)
|
||||
int gValue(int, int& gvalue, int& ctl_bit) ;
|
||||
|
||||
void print_tbls(ostream&out = cerr) ;
|
||||
int print_bits(unsigned, ostream& = cout);
|
||||
|
||||
protected:
|
||||
|
||||
#ifdef C_API
|
||||
static tbl_cache *v_tbl_cache_ptr;
|
||||
#else
|
||||
static tbl_cache v_tbl_cache;
|
||||
#endif
|
||||
|
||||
atoi_pearson *v_tbl0 , // table1
|
||||
*v_tbl1 ; // table2
|
||||
|
||||
Boolean v_long_string_core_indexed;
|
||||
|
||||
unsigned int v_no_ps, // number of partitions (buckets)
|
||||
v_p1, v_p2, // parameters p1 and p2.
|
||||
r,
|
||||
v_seed,
|
||||
t;
|
||||
|
||||
};
|
||||
|
||||
HANDLER_SIGNATURES(fast_mphf)
|
||||
|
||||
#endif
|
||||
103
cde/lib/DtMmdb/index/hash.C
Normal file
103
cde/lib/DtMmdb/index/hash.C
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: hash.cc /main/4 1996/06/11 17:21:53 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 <stdio.h>
|
||||
#include "index/hash.h"
|
||||
|
||||
ihash::ihash() : v_key_set_sz(0), v_hash_func_sz(0), v_hash_tbl_sz(0)
|
||||
{
|
||||
}
|
||||
|
||||
ihash::~ihash()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ihash::init_data_member(unsigned int a, unsigned int b, unsigned int c)
|
||||
{
|
||||
v_key_set_sz = a;
|
||||
v_hash_func_sz = b;
|
||||
v_hash_tbl_sz = c;
|
||||
}
|
||||
|
||||
|
||||
int ihash::cdr_sizeof()
|
||||
{
|
||||
return sizeof(v_key_set_sz) + sizeof(v_hash_func_sz) + sizeof(v_hash_tbl_sz);
|
||||
}
|
||||
|
||||
io_status ihash::cdrOut(buffer& buf)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "ihash::cdrOut");
|
||||
debug(cerr, v_hash_tbl_sz);
|
||||
debug(cerr, v_key_set_sz);
|
||||
*/
|
||||
buf.put(v_key_set_sz);
|
||||
buf.put(v_hash_func_sz);
|
||||
buf.put(v_hash_tbl_sz);
|
||||
return done;
|
||||
}
|
||||
|
||||
io_status ihash::cdrIn(buffer& buf)
|
||||
{
|
||||
//MESSAGE(cerr, "ihash::cdrIn");
|
||||
|
||||
buf.get(v_key_set_sz);
|
||||
buf.get(v_hash_func_sz);
|
||||
buf.get(v_hash_tbl_sz);
|
||||
/*
|
||||
debug(cerr, v_hash_tbl_sz);
|
||||
debug(cerr, v_key_set_sz);
|
||||
*/
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
91
cde/lib/DtMmdb/index/hash.h
Normal file
91
cde/lib/DtMmdb/index/hash.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: hash.h /main/4 1996/06/11 17:21:59 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _hash_h
|
||||
#define _hash_h 1
|
||||
|
||||
//#include <assert.h>
|
||||
#include "utility/buffer.h"
|
||||
#include "utility/key.h"
|
||||
|
||||
class ihash
|
||||
{
|
||||
|
||||
public:
|
||||
ihash();
|
||||
virtual ~ihash() ;
|
||||
|
||||
virtual void init_data_member(unsigned int v_key_set_sz = 0,
|
||||
unsigned int v_hash_func_sz = 0,
|
||||
unsigned int v_hash_tbl_sz = 0);
|
||||
|
||||
// status inquiry functions
|
||||
virtual int keysetsize() const { return v_key_set_sz; };
|
||||
virtual int hashtablesize() const { return v_hash_tbl_sz; };
|
||||
virtual int hashfuncsize() const { return v_hash_func_sz; };
|
||||
|
||||
// return the hash value for a key
|
||||
virtual int hashTo(const key_type&) = 0;
|
||||
|
||||
// load a set of key-oid pairs
|
||||
virtual Boolean load() { return false; };
|
||||
|
||||
// compacted disk representation In and Out functions
|
||||
virtual int cdr_sizeof();
|
||||
virtual io_status cdrOut(buffer&);
|
||||
virtual io_status cdrIn(buffer&);
|
||||
|
||||
protected:
|
||||
unsigned int v_key_set_sz;
|
||||
unsigned int v_hash_func_sz;
|
||||
unsigned int v_hash_tbl_sz;
|
||||
};
|
||||
|
||||
#endif
|
||||
162
cde/lib/DtMmdb/index/index.C
Normal file
162
cde/lib/DtMmdb/index/index.C
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: index.cc /main/6 1996/07/18 14:36:52 drk $
|
||||
*
|
||||
* 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 "index/index.h"
|
||||
|
||||
#ifdef C_API
|
||||
key_type* c_index::v_static_key_ptr;
|
||||
#define v_static_key (*v_static_key_ptr)
|
||||
#else
|
||||
key_type c_index::v_static_key(LBUFSIZ);
|
||||
#endif
|
||||
|
||||
void c_index::init_persistent_info(persistent_info* x)
|
||||
{
|
||||
root::init_persistent_info(x);
|
||||
set_mode(SWAP_ALLOWED, false);
|
||||
}
|
||||
|
||||
c_index::c_index(c_code_t c_cd) : composite(c_cd), v_inv_lists_hd(NULL)
|
||||
{
|
||||
v_cmp_selector = 0;
|
||||
}
|
||||
|
||||
oid_list_handler* c_index::operator()(int ind)
|
||||
{
|
||||
return (*v_inv_lists_hd) -> get_list( ind );
|
||||
}
|
||||
|
||||
ostream& operator <<(ostream& s, c_index&)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
oid_t c_index::first_of_invlist(const handler& q)
|
||||
{
|
||||
return first_of_invlist(handler_to_inv_idx(q));
|
||||
}
|
||||
|
||||
oid_t c_index::first_of_invlist(int ind)
|
||||
{
|
||||
oid_t x;
|
||||
oid_list_handler* y = (*this)(ind);
|
||||
|
||||
if ( y == 0 ) {
|
||||
throw(stringException("NULL oid list handler ptr"));
|
||||
}
|
||||
|
||||
if ( (*y) -> count() == 0 )
|
||||
throw(stringException("index::first_of_invlist(): empty list"));
|
||||
|
||||
x = (*y) -> operator()((*y) -> first());
|
||||
|
||||
delete y;
|
||||
|
||||
//MESSAGE(cerr, "c_index::first_of_invlist() returns: ");
|
||||
//debug(cerr, x);
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
Boolean c_index::get_key_string(const handler& t) const
|
||||
{
|
||||
ostringstream out;
|
||||
int len;
|
||||
|
||||
((handler&)t) -> asciiOut(out);
|
||||
len = out.str().size();
|
||||
v_static_key.set_size(len);
|
||||
*((char *) memcpy(v_static_key.get(), out.str().c_str(), len) + len) = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean c_index::get_key_string(const oid_t& t) const
|
||||
{
|
||||
v_static_key.reset();
|
||||
int len;
|
||||
|
||||
ostringstream out(v_static_key.get());
|
||||
t.asciiOut(out);
|
||||
|
||||
len = out.str().size();
|
||||
v_static_key.set_size(len);
|
||||
*((char *) memcpy(v_static_key.get(), out.str().c_str(), len) + len) = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int c_index::cdr_sizeof()
|
||||
{
|
||||
return composite::cdr_sizeof() + sizeof(v_cmp_selector);
|
||||
}
|
||||
|
||||
io_status c_index::cdrOut(buffer& buf)
|
||||
{
|
||||
composite::cdrOut(buf);
|
||||
buf.put(v_cmp_selector);
|
||||
return done;
|
||||
}
|
||||
|
||||
io_status c_index::cdrIn(buffer& buf)
|
||||
{
|
||||
composite::cdrIn(buf);
|
||||
buf.get(v_cmp_selector);
|
||||
return done;
|
||||
}
|
||||
|
||||
void c_index::commit()
|
||||
{
|
||||
if ( v_inv_lists_hd )
|
||||
v_inv_lists_hd -> commit();
|
||||
}
|
||||
|
||||
HANDLER_BODIES(c_index)
|
||||
142
cde/lib/DtMmdb/index/index.h
Normal file
142
cde/lib/DtMmdb/index/index.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: index.h /main/7 1996/08/21 15:52:20 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _index_h
|
||||
#define _index_h 1
|
||||
|
||||
#ifdef C_API
|
||||
#include "utility/c_stringstream.h"
|
||||
#else
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include "object/oid_list.h"
|
||||
#include "index/inv_lists.h"
|
||||
|
||||
class c_index : public composite
|
||||
{
|
||||
|
||||
public:
|
||||
c_index(c_code_t = INDEX_CODE);
|
||||
virtual ~c_index() {} ;
|
||||
|
||||
void init_persistent_info(persistent_info* x);
|
||||
|
||||
|
||||
void set_selector(int cmp) { v_cmp_selector = cmp; };
|
||||
|
||||
// iteration functions
|
||||
virtual oid_list_handler* operator()(int index);
|
||||
virtual oid_t first_of_invlist(int ind) ;
|
||||
virtual oid_t first_of_invlist(const handler&);
|
||||
|
||||
// insert index functions
|
||||
virtual Boolean batch_index_begin() { return true; };
|
||||
virtual Boolean batch_index_end() { return true; };
|
||||
virtual Boolean insert_key_loc(const handler&, const oid_t&) = 0;
|
||||
virtual Boolean insert_key_loc(const oid_t&, const oid_t&) = 0;
|
||||
virtual Boolean load(const char*) { return true; };
|
||||
|
||||
// remove index functions
|
||||
virtual Boolean remove_loc(handler&, const oid_t&) = 0;
|
||||
virtual Boolean remove_loc(const oid_t&, const oid_t&) = 0;
|
||||
|
||||
// update index function
|
||||
virtual Boolean update_streampos(handler& old_obj,
|
||||
handler& new_obj,
|
||||
mmdb_pos_t pos
|
||||
) = 0;
|
||||
|
||||
// retreval functions
|
||||
virtual oid_list_handler* get_loc_list(const oid_t&)=0;
|
||||
virtual oid_list_handler* get_loc_list(const handler&)=0;
|
||||
virtual int invlist_length(handler&) = 0;
|
||||
|
||||
// translate a query to an index of an inv_list
|
||||
virtual size_t handler_to_inv_idx(const handler& query) = 0;
|
||||
|
||||
// status inquiry functions
|
||||
int bound_to() const { return v_cmp_selector; } ;
|
||||
virtual Boolean sorted() const = 0;
|
||||
|
||||
virtual int cdr_sizeof();
|
||||
virtual io_status cdrOut(buffer&);
|
||||
virtual io_status cdrIn(buffer&);
|
||||
void commit();
|
||||
|
||||
// i/o function
|
||||
friend ostream& operator <<(ostream& s, c_index& t) ;
|
||||
|
||||
#ifdef C_API
|
||||
friend void initialize_MMDB();
|
||||
friend void quit_MMDB();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
Boolean get_key_string(const handler&) const;
|
||||
Boolean get_key_string(const oid_t&) const;
|
||||
|
||||
protected:
|
||||
|
||||
#ifdef C_API
|
||||
static key_type* v_static_key_ptr;
|
||||
#else
|
||||
static key_type v_static_key;
|
||||
#endif
|
||||
|
||||
int v_cmp_selector;
|
||||
inv_lists_handler *v_inv_lists_hd;
|
||||
};
|
||||
|
||||
typedef c_index* indexPtr;
|
||||
|
||||
HANDLER_SIGNATURES(c_index)
|
||||
|
||||
#endif
|
||||
175
cde/lib/DtMmdb/index/inv_lists.C
Normal file
175
cde/lib/DtMmdb/index/inv_lists.C
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: inv_lists.cc /main/5 1996/07/18 14:37:46 drk $
|
||||
*
|
||||
* 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 "index/inv_lists.h"
|
||||
#include "utility/funcs.h"
|
||||
|
||||
|
||||
inv_lists::inv_lists(c_code_t c_cd) : oid_list(c_cd)
|
||||
{
|
||||
//set_mode(HEALTH, true);
|
||||
}
|
||||
|
||||
inv_lists::~inv_lists()
|
||||
{
|
||||
}
|
||||
|
||||
Boolean inv_lists::insert_list_pinned(int index, oid_list& lst)
|
||||
{
|
||||
if ( lst.count() == 0 ) {
|
||||
throw(boundaryException(0, lst.count(), index));
|
||||
}
|
||||
|
||||
oid_list_handler list_hd(lst.count(), storage_ptr);
|
||||
|
||||
for ( int i=1; i<=lst.count(); i++ )
|
||||
list_hd -> update_component(i, lst(i)) ;
|
||||
|
||||
oid_list::update_component(index, list_hd.its_oid()) ;
|
||||
|
||||
set_mode(UPDATE, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean inv_lists::append_list(oid_list& lst)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "append a inv list");
|
||||
lst.asciiOut(cerr); cerr << "\n";
|
||||
*/
|
||||
|
||||
handler hd(OID_LIST_CODE, storage_ptr);
|
||||
|
||||
oid_list_handler& lst_handler = *(oid_list_handler*)&hd;
|
||||
|
||||
|
||||
lst_handler -> expand_space(lst.count());
|
||||
|
||||
for ( int i=1; i<=lst.count(); i++ )
|
||||
lst_handler -> update_component(i, lst(i)) ;
|
||||
|
||||
oid_list::insert_component(hd.its_oid()) ;
|
||||
|
||||
set_mode(UPDATE, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean inv_lists::remove_list(int index)
|
||||
{
|
||||
update_component(index, ground);
|
||||
return true;
|
||||
}
|
||||
|
||||
oid_list_handler* inv_lists::get_list(int index)
|
||||
{
|
||||
oid_t x((*this)(index));
|
||||
|
||||
if ( x.eq(ground) == true ) {
|
||||
return 0;
|
||||
} else {
|
||||
return new oid_list_handler(x, storage_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
oid_list_handler* inv_lists::get_list(mmdb_pos_t)
|
||||
{
|
||||
throw( stringException("get_list(): not implemented yet"));
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
ostream& operator <<(ostream&s, inv_lists& o)
|
||||
{
|
||||
for (int i=0; i < o.count(); i++) {
|
||||
oid_list_handler* x = o.get_list(i);
|
||||
(*x) -> asciiOut(s);
|
||||
delete x;
|
||||
s << "\n";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void inv_lists::insert_to_list(int index, oid_t& id)
|
||||
{
|
||||
if ( !INRANGE(index, 1, (int) v_sz) ) {
|
||||
throw(boundaryException(1, v_sz, index));
|
||||
}
|
||||
|
||||
oid_t list_id = (*this)(index);
|
||||
|
||||
/*
|
||||
MESSAGE(cerr, "inv::insert");
|
||||
debug(cerr, index);
|
||||
*/
|
||||
|
||||
if ( INRANGE((short)list_id.ccode(), 0, 1) &&
|
||||
id.ccode() != OID_LIST_CODE
|
||||
) {
|
||||
|
||||
update_component(index, id);
|
||||
|
||||
} else {
|
||||
if ( list_id.ccode() != OID_LIST_CODE ) {
|
||||
oid_list_handler y(OID_LIST_CODE, storage_ptr);
|
||||
y -> insert_component(list_id);
|
||||
update_component(index, y.its_oid());
|
||||
y -> insert_component(id);
|
||||
} else {
|
||||
oid_list_handler y( list_id, storage_ptr);
|
||||
y -> insert_component(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MMDB_BODIES(inv_lists)
|
||||
HANDLER_BODIES(inv_lists)
|
||||
83
cde/lib/DtMmdb/index/inv_lists.h
Normal file
83
cde/lib/DtMmdb/index/inv_lists.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: inv_lists.h /main/5 1996/07/18 14:38:10 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _inv_lists_h
|
||||
#define _inv_lists_h 1
|
||||
|
||||
#include "storage/unixf_storage.h"
|
||||
#include "object/oid_list.h"
|
||||
|
||||
class inv_lists : public oid_list
|
||||
{
|
||||
|
||||
public:
|
||||
inv_lists(c_code_t = INV_LISTS_CODE) ;
|
||||
virtual ~inv_lists() ;
|
||||
|
||||
MMDB_SIGNATURES(inv_lists);
|
||||
|
||||
// get the invlist
|
||||
virtual oid_list_handler* get_list(int index) ;
|
||||
// virtual oid_list_handler* get_list(mmdb_pos_t pod) ;
|
||||
|
||||
// update functions
|
||||
Boolean append_list(oid_list&);
|
||||
Boolean insert_list_pinned(int index, oid_list&);
|
||||
Boolean remove_list(int index);
|
||||
void insert_to_list(int index, oid_t& id);
|
||||
|
||||
// I/O function
|
||||
friend ostream& operator <<(ostream&, inv_lists&) ;
|
||||
|
||||
};
|
||||
|
||||
HANDLER_SIGNATURES(inv_lists)
|
||||
|
||||
#endif
|
||||
295
cde/lib/DtMmdb/index/mphf_index.C
Normal file
295
cde/lib/DtMmdb/index/mphf_index.C
Normal file
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: mphf_index.cc /main/5 1996/07/18 14:38:37 drk $
|
||||
*
|
||||
* Copyright (c) 1992 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 "index/mphf_index.h"
|
||||
|
||||
#ifdef C_API
|
||||
#define v_static_key (*v_static_key_ptr)
|
||||
#endif
|
||||
|
||||
|
||||
mphf_index::mphf_index() : c_index(MPHF_INDEX_CODE), f_key_file_name(0)
|
||||
{
|
||||
//MESSAGE(cerr, " mphf_index::mphf_index():");
|
||||
//debug(cerr, (void*)this);
|
||||
|
||||
v_mphf = 0;
|
||||
v_inv_lists_hd = 0;
|
||||
v_key_loc_pair_out = NULL;
|
||||
}
|
||||
|
||||
void mphf_index::init_data_member(fast_mphf_handler* mp,
|
||||
inv_lists_handler* inv)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, " mphf_index::init_data_member():");
|
||||
debug(cerr, (void*)v_mphf);
|
||||
debug(cerr, (void*)(v_mphf->operator->()));
|
||||
*/
|
||||
v_mphf = mp;
|
||||
v_inv_lists_hd = inv;
|
||||
set_mode(HEALTH, true);
|
||||
}
|
||||
|
||||
|
||||
mphf_index::~mphf_index()
|
||||
{
|
||||
delete f_key_file_name;
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Need not to delete index object handlers, as they
|
||||
// are handled by the object cache. qfc 6-17-93
|
||||
////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
Boolean
|
||||
mphf_index::insert_key_loc(const oid_t& id, const oid_t& loc)
|
||||
{
|
||||
get_key_string(id);
|
||||
|
||||
*v_key_loc_pair_out << v_static_key << "\n";
|
||||
loc.asciiOut(*v_key_loc_pair_out);
|
||||
*v_key_loc_pair_out << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean
|
||||
mphf_index::insert_key_loc(const handler& hd, const oid_t& loc)
|
||||
{
|
||||
get_key_string(hd);
|
||||
|
||||
*v_key_loc_pair_out << v_static_key << "\n";
|
||||
loc.asciiOut(*v_key_loc_pair_out);
|
||||
*v_key_loc_pair_out << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean mphf_index::remove_loc(const oid_t&, const oid_t&)
|
||||
{
|
||||
throw(stringException("mphf_index::remove_index(): not applicable"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean mphf_index::remove_loc(handler&, const oid_t&)
|
||||
{
|
||||
throw(stringException("remove_index(): not applicable"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Boolean mphf_index::update_streampos(handler& ,
|
||||
handler& ,
|
||||
mmdb_pos_t
|
||||
)
|
||||
{
|
||||
throw(stringException("update_index(): not applicable"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Boolean mphf_index::load(const char* key_set)
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, " mphf_index::load():");
|
||||
debug(cerr, (void*)this);
|
||||
debug(cerr, (void*)(v_mphf->operator->()));
|
||||
*/
|
||||
|
||||
(*v_mphf) -> build(key_set);
|
||||
|
||||
fstream in(key_set, ios::in);
|
||||
|
||||
v_sz = (*v_mphf) -> keysetsize();
|
||||
(*v_inv_lists_hd) -> expand_space(v_sz);
|
||||
|
||||
key_type key(LBUFSIZ);
|
||||
|
||||
#ifdef DEBUG
|
||||
int i = 0;
|
||||
#endif
|
||||
|
||||
while ( in >> key ) {
|
||||
|
||||
oid_t key_id(c_code_t(0), 0);
|
||||
|
||||
key_id.asciiIn(in);
|
||||
|
||||
#ifdef DEBUG
|
||||
if ( i % 1000 == 0 && i != 0 ) {
|
||||
cerr << i;
|
||||
MESSAGE(cerr, " keys processed");
|
||||
MESSAGE(cerr, "========");
|
||||
}
|
||||
i++;
|
||||
#endif
|
||||
|
||||
|
||||
int hash = (*v_mphf) -> hashTo(key);
|
||||
|
||||
(*v_inv_lists_hd) -> insert_to_list(hash+1, key_id);
|
||||
|
||||
}
|
||||
|
||||
#ifndef MPHF_DEBUG
|
||||
del_file(key_set, 0);
|
||||
#endif
|
||||
|
||||
set_mode(HEALTH, true);
|
||||
set_mode(UPDATE, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
oid_list_handler* mphf_index::get_loc_list(const oid_t& )
|
||||
{
|
||||
MESSAGE(cerr, "get_loc_list(): not implemented yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t mphf_index::handler_to_inv_idx(const handler& t)
|
||||
{
|
||||
get_key_string(t);
|
||||
//debug(cerr, v_static_key);
|
||||
return (*v_mphf) -> hashTo(v_static_key);
|
||||
}
|
||||
|
||||
oid_list_handler* mphf_index::get_loc_list(const handler& t)
|
||||
{
|
||||
return (*this)(handler_to_inv_idx(t) + 1) ;
|
||||
}
|
||||
|
||||
int mphf_index::invlist_length(handler& t)
|
||||
{
|
||||
oid_list_handler* x = get_loc_list(t);
|
||||
return (*x) -> count();
|
||||
}
|
||||
|
||||
ostream& operator << (ostream&s, mphf_index& v)
|
||||
{
|
||||
int ind = v.first();
|
||||
while (ind != 0) {
|
||||
v.next(ind);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Boolean mphf_index::batch_index_begin()
|
||||
{
|
||||
/*
|
||||
MESSAGE(cerr, "batch_index_begin()");
|
||||
debug(cerr, v_cmp_selector);
|
||||
debug(cerr, count());
|
||||
debug(cerr, int(this));
|
||||
*/
|
||||
|
||||
if ( count() > 0 ) {
|
||||
throw(stringException("batch_index_begin(): index exists"));
|
||||
}
|
||||
|
||||
f_key_file_name =
|
||||
strdup(form("%s/keys.%d_%d",
|
||||
get_store() -> my_path(), f_oid.ccode(), f_oid.icode()));
|
||||
|
||||
v_key_loc_pair_out = new fstream(f_key_file_name, ios::out);
|
||||
|
||||
return (( *v_key_loc_pair_out ) ? true : false );
|
||||
}
|
||||
|
||||
Boolean mphf_index::batch_index_end()
|
||||
{
|
||||
v_key_loc_pair_out -> close();
|
||||
delete v_key_loc_pair_out;
|
||||
|
||||
return load(f_key_file_name);
|
||||
}
|
||||
|
||||
oid_t mphf_index::first_of_invlist(int ind)
|
||||
{
|
||||
oid_t x((*v_inv_lists_hd) -> operator()(ind+1));
|
||||
|
||||
if ( x.ccode() == OID_LIST_CODE ) {
|
||||
oid_list_handler* y = (*this)(ind);
|
||||
if ( (*y) -> count() > 0 ) {
|
||||
return (*y) -> operator()(1);
|
||||
} else {
|
||||
throw(stringException("first_of_invlist(): empty list"));
|
||||
}
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
oid_t mphf_index::first_of_invlist(const handler& t)
|
||||
{
|
||||
int hash = handler_to_inv_idx(t);
|
||||
/*
|
||||
debug(cerr, hash);
|
||||
*/
|
||||
|
||||
|
||||
oid_t x((*v_inv_lists_hd) -> operator()(hash+1));
|
||||
|
||||
//debug(cerr, x);
|
||||
|
||||
if ( x.ccode() == OID_LIST_CODE ) {
|
||||
oid_list_handler* y = (*this)(hash);
|
||||
if ( (*y) -> count() > 0 ) {
|
||||
return (*y) -> operator()(1);
|
||||
} else {
|
||||
throw(stringException("first_of_invlist(): empty list"));
|
||||
}
|
||||
} else {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
MMDB_BODIES(mphf_index)
|
||||
HANDLER_BODIES(mphf_index)
|
||||
121
cde/lib/DtMmdb/index/mphf_index.h
Normal file
121
cde/lib/DtMmdb/index/mphf_index.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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 libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: mphf_index.h /main/5 1996/07/18 14:39:04 drk $
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _mphf_index_h
|
||||
#define _mphf_index_h 1
|
||||
|
||||
#include "utility/funcs.h"
|
||||
#include "index/index.h"
|
||||
#include "index/fast_mphf.h"
|
||||
#include "index/inv_lists.h"
|
||||
|
||||
/**********************************************************/
|
||||
// An index class consisted of a MPHF object and an
|
||||
// inverted list.
|
||||
/**********************************************************/
|
||||
class mphf_index : public c_index
|
||||
{
|
||||
|
||||
public:
|
||||
mphf_index() ;
|
||||
virtual ~mphf_index() ;
|
||||
|
||||
void init_data_member(fast_mphf_handler*, inv_lists_handler*);
|
||||
|
||||
MMDB_SIGNATURES(mphf_index);
|
||||
|
||||
// insert index functions
|
||||
virtual Boolean batch_index_begin() ;
|
||||
virtual Boolean batch_index_end() ;
|
||||
virtual Boolean insert_key_loc(const handler&, const oid_t&) ;
|
||||
virtual Boolean insert_key_loc(const oid_t&, const oid_t&) ;
|
||||
virtual Boolean load(const char* key_set) ;
|
||||
|
||||
// remove index functions
|
||||
virtual Boolean remove_loc(handler&, const oid_t& ) ;
|
||||
virtual Boolean remove_loc(const oid_t&, const oid_t& );
|
||||
|
||||
// update index function
|
||||
virtual Boolean update_streampos(handler& old_obj,
|
||||
handler& new_obj,
|
||||
mmdb_pos_t pos
|
||||
) ;
|
||||
|
||||
// retrieval functions
|
||||
virtual oid_list_handler* get_loc_list(const oid_t&);
|
||||
virtual oid_list_handler* get_loc_list(const handler&);
|
||||
virtual int invlist_length(handler&) ;
|
||||
|
||||
virtual oid_t first_of_invlist(int ind);
|
||||
virtual oid_t first_of_invlist(const handler&);
|
||||
|
||||
//
|
||||
size_t handler_to_inv_idx(const handler& query);
|
||||
|
||||
// status inquiry functions
|
||||
virtual Boolean sorted() const { return false; };
|
||||
|
||||
// io function
|
||||
friend ostream& operator <<(ostream&, mphf_index&);
|
||||
|
||||
protected:
|
||||
|
||||
protected:
|
||||
fstream* v_key_loc_pair_out;
|
||||
|
||||
private:
|
||||
fast_mphf_handler *v_mphf; // hash func
|
||||
|
||||
char* f_key_file_name;
|
||||
};
|
||||
|
||||
HANDLER_SIGNATURES(mphf_index)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user