Commit a062735d authored by Antony T Curtis's avatar Antony T Curtis

Cleanup, simplify and optimize. Change makefile a little so that we have debug...

Cleanup, simplify and optimize. Change makefile a little so that we have debug symbols for the graph core.
parent b27a83d5
......@@ -59,9 +59,9 @@ noinst_HEADERS = ha_oqgraph.h \
graphcore-graph.h graphcore-types.h graphcore.h
# oqgraph_probes.h
noinst_LTLIBRARIES = libgraphcore.la
libgraphcore_la_SOURCES = graphcore.cc graphcore-graph.cc oqgraph_shim.cc oqgraph_thunk.cc
libgraphcore_la_CXXFLAGS = $(ORIG_CXXFLAGS) $(BOOST_CXXFLAGS)
#noinst_LTLIBRARIES = libgraphcore.la
#libgraphcore_la_SOURCES = graphcore.cc graphcore-graph.cc oqgraph_shim.cc oqgraph_thunk.cc
#libgraphcore_la_CXXFLAGS = $(ORIG_CXXFLAGS) $(BOOST_CXXFLAGS)
if BUILD_OQGRAPH_FOR_MYSQL
......@@ -73,8 +73,27 @@ endif !BUILD_OQGRAPH_STANDALONE
EXTRA_LTLIBRARIES = ha_oqgraph.la
mysqlplugin_LTLIBRARIES = @plugin_oqgraph_shared_target@
ha_oqgraph_la_SOURCES = ha_oqgraph.cc oqgraph_judy.cc
ha_oqgraph_la_LIBADD = libgraphcore.la
ha_oqgraph_la_SOURCES = ha_oqgraph.cc oqgraph_judy.cc \
graphcore.cc graphcore-graph.cc \
oqgraph_thunk.cc oqgraph_shim.cc
#ha_oqgraph_la_LIBADD = libgraphcore.la
ha_oqgraph_la-graphcore.lo: graphcore.cc
$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ORIG_CXXFLAGS) $(BOOST_CXXFLAGS) $(CXXFLAGS) -MT ha_oqgraph_la-graphcore.lo -MD -MP -MF $(DEPDIR)/ha_oqgraph_la-graphcore.Tpo -c -o ha_oqgraph_la-graphcore.lo `test -f 'graphcore.cc' || echo '$(srcdir)/'`graphcore.cc
mv -f $(DEPDIR)/ha_oqgraph_la-graphcore.Tpo $(DEPDIR)/ha_oqgraph_la-graphcore.Plo
ha_oqgraph_la-graphcore-graph.lo: graphcore-graph.cc
$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ORIG_CXXFLAGS) $(BOOST_CXXFLAGS) $(CXXFLAGS) -MT ha_oqgraph_la-graphcore-graph.lo -MD -MP -MF $(DEPDIR)/ha_oqgraph_la-graphcore-graph.Tpo -c -o ha_oqgraph_la-graphcore-graph.lo `test -f 'graphcore.cc' || echo '$(srcdir)/'`graphcore-graph.cc
mv -f $(DEPDIR)/ha_oqgraph_la-graphcore-graph.Tpo $(DEPDIR)/ha_oqgraph_la-graphcore-graph.Plo
ha_oqgraph_la-oqgraph_shim.lo: oqgraph_shim.cc
$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ORIG_CXXFLAGS) $(BOOST_CXXFLAGS) $(CXXFLAGS) -MT ha_oqgraph_la-oqgraph_shim.lo -MD -MP -MF $(DEPDIR)/ha_oqgraph_la-oqgraph_shim.Tpo -c -o ha_oqgraph_la-oqgraph_shim.lo `test -f 'oqgraph_shim.cc' || echo '$(srcdir)/'`oqgraph_shim.cc
mv -f $(DEPDIR)/ha_oqgraph_la-oqgraph_shim.Tpo $(DEPDIR)/ha_oqgraph_la-oqgraph_shim.Plo
ha_oqgraph_la-oqgraph_thunk.lo: oqgraph_thunk.cc
$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ORIG_CXXFLAGS) $(BOOST_CXXFLAGS) $(CXXFLAGS) -MT ha_oqgraph_la-oqgraph_thunk.lo -MD -MP -MF $(DEPDIR)/ha_oqgraph_la-oqgraph_thunk.Tpo -c -o ha_oqgraph_la-oqgraph_thunk.lo `test -f 'oqgraph_thunk.cc' || echo '$(srcdir)/'`oqgraph_thunk.cc
mv -f $(DEPDIR)/ha_oqgraph_la-oqgraph_thunk.Tpo $(DEPDIR)/ha_oqgraph_la-oqgraph_thunk.Plo
# if HAVE_DTRACE
# ha_oqgraph_la_LIBADD += oqgraph_probes.o
......
......@@ -35,18 +35,6 @@ namespace boost
{
typedef oqgraph3::graph Graph;
template <>
struct hash<graph_traits<oqgraph3::graph>::vertex_descriptor>
: public std::unary_function<
graph_traits<oqgraph3::graph>::vertex_descriptor, std::size_t>
{
std::size_t operator()(
const graph_traits<oqgraph3::graph>::vertex_descriptor& v) const
{
return boost::hash_value(v->id);
}
};
template<typename IndexMap = identity_property_map>
struct two_bit_judy_map
{
......@@ -54,15 +42,15 @@ namespace boost
typedef two_bit_color_type value_type;
typedef void reference;
typedef read_write_property_map_tag category;
open_query::judy_bitset msb;
open_query::judy_bitset lsb;
IndexMap index;
two_bit_judy_map(const IndexMap& i)
: index(i)
{ }
friend two_bit_color_type get(
const two_bit_judy_map<IndexMap>& pm,
typename property_traits<IndexMap>::key_type key)
......@@ -70,7 +58,7 @@ namespace boost
typename property_traits<IndexMap>::value_type i = get(pm.index, key);
return two_bit_color_type((2*int(pm.msb.test(i))) | int(pm.lsb.test(i)));
}
friend void put(
two_bit_judy_map<IndexMap>& pm,
typename property_traits<IndexMap>::key_type key,
......@@ -81,7 +69,7 @@ namespace boost
pm.lsb.set(i, value & 1);
}
};
template<typename IndexMap>
inline two_bit_judy_map<IndexMap>
make_two_bit_judy_map(const IndexMap& index)
......@@ -89,7 +77,7 @@ namespace boost
return two_bit_judy_map<IndexMap>(index);
}
template <typename Type>
struct default_lazy_initializer
{
......@@ -119,11 +107,11 @@ namespace boost
const Type& operator()(const Key&) const { return _; }
const Type _;
};
template <typename Type>
value_initializer<Type> make_value_initializer(const Type& value)
{ return value_initializer<Type>(value); }
template <typename Key>
struct identity_initializer
......@@ -139,12 +127,12 @@ namespace boost
typedef typename Container::value_type::second_type value_type;
typedef value_type& reference;
typedef lvalue_property_map_tag category;
lazy_property_map(Container& m, Generator g= Generator())
: _m(m)
, _g(g)
{ }
reference operator[](const key_type& k) const
{
typename Container::iterator found= _m.find(k);
......@@ -154,7 +142,7 @@ namespace boost
}
return found->second;
}
void set(const key_type& k, const value_type& v)
{ _m[k] = v; }
......@@ -162,7 +150,7 @@ namespace boost
{
return s[k];
}
friend void put(self& s, const key_type& k, const value_type& v)
{ s.set(k, v); }
......@@ -175,61 +163,6 @@ namespace boost
make_lazy_property_map(Container& c, Generator g)
{ return lazy_property_map<Container, Generator>(c, g); }
#if 0
struct map_wra
struct property_traits< unordered_map_wrapper<K,T,H,P,A
template <class K, class T, class H, class P, class A>
struct property_traits< unordered_map<K,T,H,P,A> > {
typedef T value_type;
typedef K key_type;
typedef T& reference;
struct category
: public read_write_property_map_tag
, public lvalue_property_map_tag
{ };
friend reference get(
unordered_map<K,T,H,P,A>& m,
const key_type& k)
{
return m[k];
}
friend void put(
unordered_map<K,T,H,P,A>& m,
const key_type& k,
const value_type& v)
{
m[k]= v;
}
};
//template <class K, class T, class H, class P, class A>
//property_traits< unordered_map<K,T,H,P,A> >::reference
//get(unordered_map<K,T,H,P,A>& m,
// const property_traits< unordered_map<K,T,H,P,A> >::key_type& k)
//{ return m[ k ]; }
//template <class K, class T, class H, class P, class A>
//void put(
// unordered_map<K,T,H,P,A>& m,
// const property_traits< unordered_map<K,T,H,P,A> >::key_type& k,
// const property_traits< unordered_map<K,T,H,P,A> >::value_type& v)
//{ m[ k ] = v; }
//template <class K, class T, class H, class P, class A>
//property_traits< unordered_map<K,T,H,P,A>::reference
//get(unordered_map<K,T,H,P,A>& m,
// const graph_traits<oqgraph3::graph>::vertex_descriptor& v)
//{ return m[ v->id ]; }
#endif
}
#endif
......@@ -345,7 +345,7 @@ namespace open_query {
oqgraph_visit_dist<P,D>
make_oqgraph_visit_dist(const P& p, const D& d, stack_cursor *cursor)
{ return oqgraph_visit_dist<P,D>(p, d, cursor); }
template<bool record_weight, typename goal_filter, typename P>
struct GRAPHCORE_INTERNAL oqgraph_goal
......@@ -402,7 +402,7 @@ namespace open_query {
stack_cursor &m_cursor;
P m_p;
};
template<bool record_weight, typename goal_filter, typename P>
oqgraph_goal<record_weight, goal_filter, P>
make_oqgraph_goal(const Vertex& goal, const P& p, stack_cursor *cursor)
......@@ -820,7 +820,7 @@ namespace open_query
)
),
make_two_bit_judy_map(get(vertex_index, share->g)));
break;
break;
case BREADTH_FIRST:
breadth_first_visit(share->g, *orig, Q,
make_bfs_visitor(
......@@ -1060,9 +1060,8 @@ int edges_cursor::fetch_row(const row &row_info, row &result)
{
edge_iterator it, end;
reference ref;
size_t count= position;
for (tie(it, end)= edges(share->g); count && it != end; ++it, --count)
;
tie(it, end)= edges(share->g);
it+= position;
if (it != end)
ref= reference(position+1, *it);
if (int res= fetch_row(row_info, result, ref))
......
......@@ -274,13 +274,13 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
reinterpret_cast<oqgraph_table_option_struct*>(table->s->option_struct);
error_message.length(0);
const char* p= strend(name)-1;
while (p > name && *p != '\\' && *p != '/')
--p;
init_tmp_table_share(
thd, share, table->s->db.str, table->s->db.length,
thd, share, table->s->db.str, table->s->db.length,
options->table_name, "");
size_t tlen= strlen(options->table_name);
......@@ -303,7 +303,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
free_table_share(share);
return thd->main_da.sql_errno();
}
if (ha_create_table_from_engine(thd, table->s->db.str, options->table_name))
{
free_table_share(share);
......@@ -313,7 +313,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
thd->clear_error();
continue;
}
if (int err= share->error)
{
open_table_error(share, share->error, share->open_errno, share->errarg);
......@@ -341,7 +341,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
}
edges->reginfo.lock_type= TL_READ;
edges->tablenr= thd->current_tablenr++;
edges->status= STATUS_NO_RECORD;
edges->file->ha_start_of_new_statement();
......@@ -349,18 +349,18 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
edges->pos_in_table_list= 0;
edges->clear_column_bitmaps();
bfill(table->record[0], table->s->null_bytes, 255);
bfill(table->record[1], table->s->null_bytes, 255);
bfill(table->record[1], table->s->null_bytes, 255);
// We expect fields origid, destid and optionally weight
origid= destid= weight= 0;
if (!edges->file)
{
print_error("Some error occurred opening table '%s'", options->table_name);
free_table_share(share);
return -1;
}
for (Field **field= edges->field; *field; ++field)
{
if (strcmp(options->origid, (*field)->field_name))
......@@ -377,7 +377,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
origid = *field;
break;
}
for (Field **field= edges->field; *field; ++field)
{
if (strcmp(options->destid, (*field)->field_name))
......@@ -394,7 +394,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
destid = *field;
break;
}
for (Field **field= edges->field; options->weight && *field; ++field)
{
if (strcmp(options->weight, (*field)->field_name))
......@@ -411,7 +411,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
weight = *field;
break;
}
if (!origid || !destid || (!weight && options->weight))
{
print_error("Data columns missing on table '%s'", options->table_name);
......@@ -419,7 +419,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
free_table_share(share);
return -1;
}
if (!(graph_share = oqgraph::create(edges, origid, destid, weight)))
{
print_error("Unable to create graph instance.");
......@@ -428,9 +428,9 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
return -1;
}
ref_length= oqgraph::sizeof_ref;
graph = oqgraph::create(graph_share);
return 0;
}
......
......@@ -111,11 +111,11 @@ class ha_oqgraph: public handler
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
enum thr_lock_type lock_type);
int cmp_ref(const byte *ref1, const byte *ref2);
bool get_error_message(int error, String* buf);
void print_error(const char* fmt, ...);
private:
void update_key_stats();
String error_message;
......
......@@ -90,6 +90,19 @@ open_query::judy_bitset::size_type open_query::judy_bitset::count() const
return rc;
}
open_query::judy_bitset& open_query::judy_bitset::set(const judy_bitset& src)
{
if (!src.empty())
{
for (size_type pos= src.find_first(); pos != npos; pos= src.find_next(pos))
{
set(pos);
}
}
return *this;
}
open_query::judy_bitset::size_type open_query::judy_bitset::find_first() const
{
int rc;
......
......@@ -41,9 +41,21 @@ namespace open_query
: array(0)
{ }
judy_bitset(const judy_bitset& src)
: array(0)
{
set(src);
}
~judy_bitset()
{ clear(); }
judy_bitset& operator=(const judy_bitset& src)
{
clear();
return set(src);
}
void clear();
bool empty() const { return !array; }
bool none() const { return npos == find_first(); }
......@@ -56,6 +68,8 @@ namespace open_query
return setbit(n);
}
judy_bitset& set(const judy_bitset& src);
judy_bitset& reset(size_type n);
judy_bitset& flip(size_type n);
bool test(size_type) const;
......@@ -85,7 +99,7 @@ namespace open_query
{ if (value) j.flip(n); return *this; }
reference& operator-=(bool value)
{ if (value) j.reset(n); return *this; }
bool operator~() const { return !j.test(n); }
operator bool() const { return j.test(n); }
reference& flip() { j.flip(n); return *this; }
......@@ -94,10 +108,10 @@ namespace open_query
judy_bitset& j;
size_type n;
};
reference operator[](size_type n) { return reference(*this, n); }
bool operator[](size_type n) const { return test(n); }
size_type find_first() const;
size_type find_next(size_type n) const;
private:
......
......@@ -26,3 +26,51 @@
#include "oqgraph_shim.h"
bool oqgraph3::edge_iterator::seek()
{
if (!_graph->_cursor ||
_graph->_rnd_pos > _offset ||
_graph->_cursor != _graph->_rnd_cursor.operator->())
{
_graph->_rnd_pos= 0;
_graph->_rnd_cursor= new cursor(_graph);
if (_graph->_rnd_cursor->seek_to(boost::none, boost::none))
_graph->_rnd_pos= size_t(-1);
}
while (_graph->_rnd_pos < _offset)
{
if (_graph->_rnd_cursor->seek_next())
{
_offset = size_t(-1);
return true;
}
_graph->_rnd_pos++;
}
return false;
}
oqgraph3::edge_iterator::value_type oqgraph3::edge_iterator::operator*()
{
seek();
return *_graph->_rnd_cursor;
}
bool oqgraph3::edge_iterator::operator==(const self& x)
{
if (_offset == size_t(-1) && x._offset != size_t(-1))
return const_cast<edge_iterator&>(x).seek();
if (_offset != size_t(-1) && x._offset == size_t(-1))
return seek();
return _offset == x._offset;
}
bool oqgraph3::edge_iterator::operator!=(const self& x)
{
if (_offset == size_t(-1) && x._offset != size_t(-1))
return !const_cast<edge_iterator&>(x).seek();
if (_offset != size_t(-1) && x._offset == size_t(-1))
return !seek();
return _offset != x._offset;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment