// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // Copyright Andrew Sutton 2007 // // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_FCA_SET_CONTEXT_HPP #define BOOST_FCA_SET_CONTEXT_HPP #include #include #include namespace boost { namespace fca { // A context defines the set of objects and attributes under consideration // for FCA. Exactly, how those sets of objects are maintained is a matter // of implementation. For example, we could use std sets, or we could use // bitsets (with some complexities). The basic idea is that the type of // set used by the context must be used by the relation, the concepts and // the lattice. // The set context uses a std::set to exchange information about objects // and attributes. This is a natural choice when the amount of data to // be analyzed is relatively small. However, this can hurt performance // when for large datasets due to repeated copying. However, this does // provide the most natural interface for working with objects and // attributes. // // Note that the object type and attribute type must be copy constructible, // and less-than comparable. template class set_context { public: typedef ObjectType object_type; typedef std::set object_set; typedef AttributeType attribute_type; typedef std::set attribute_set; // Default constructor. Use this with care since the only real way // to get data into this object is to assign over it. set_context() : m_objs() , m_atts() { } // Copy constructor set_context(const set_context& x) : m_objs(x.m_objs) , m_atts(x.m_atts) { } // Iterator constructor template set_context(ObjIter oi, ObjIter oend, AttIter ai, AttIter aend) : m_objs() , m_atts() { initialize(oi, oend, ai, aend); } // Container constructor (for convenience) template set_context(ObjectSet& o, AttributeSet& a) : m_objs() , m_atts() { initialize(o.begin(), o.end(), a.begin(), a.end()); } set_context& operator =(const set_context& x) { set_context tmp(x); tmp.swap(*this); return *this; } // Return the number of objects. std::size_t num_objects() const { return m_objs.size(); } // Get the set of all objects. const object_set& objects() const { return m_objs; } // Get the set all attributes. const attribute_set& attributes() const { return m_atts; } // Get the number of attributes. std::size_t num_attributes() const { return m_atts.size(); } // Swap the object and attribute contents of this and the other object. void swap(set_context& x) { m_objs.swap(x.m_objs); m_atts.swap(x.m_atts); } private: template void initialize(ObjIter oi, ObjIter oend, AttIter ai, AttIter aend) { std::copy(oi, oend, std::inserter(m_objs, m_objs.begin())); std::copy(ai, aend, std::inserter(m_atts, m_atts.begin())); } private: object_set m_objs; attribute_set m_atts; }; } /* namespace fca */ } /* namespace boost */ #include #endif