Difference between revisions of "GSoC 2016 Better data structure for selections"
(Created page with "This page contains information about "Better data structure for selections" implemented by Adrian Boguszewski. The mentor is User:Tweenk|Krzysztof...") |
|||
Line 1: | Line 1: | ||
This page contains information about "Better data structure for selections" implemented by [[User:AdrianBoguszewski|Adrian Boguszewski]]. The mentor is [[User:Tweenk|Krzysztof Kosiński]]. | This page contains information about "Better data structure for selections" implemented by [[User:AdrianBoguszewski|Adrian Boguszewski]]. The mentor is [[User:Tweenk|Krzysztof Kosiński]]. | ||
The code is avaiable here: [https://code.launchpad.net/~adrianboguszewski/inkscape/adrian]. It has been merged into trunk in rev. 15047. | |||
==Project== | ==Project== | ||
===Goal=== | ===Goal=== | ||
This project would involve implementing an <code>Inkscape::ObjectSet</code> object that would serve as a base for <code>Inkscape::Selection</code>. The internal data structure should support fast lookup (checking whether a given object belongs to the set) and preserve the order of insertion (so that we can still determine which object was selected first or last). Internally, <code>ObjectSet</code> can be based on a Boost multi-index container with a list index and a hash index. | |||
===Implementation=== | ===Implementation=== | ||
Following work has been done: | |||
* created ObjectSet class to be a base class for Selection - ObjectSet has a multi_index_container from Boost [http://www.boost.org/doc/libs/1_61_0/libs/multi_index/doc/tutorial/basics.html] instead many containers like vectors, lists and sets | |||
* created appropiate tests for this class in GoogleTest framework | |||
* replaced some functions returning vector to return range [http://www.boost.org/doc/libs/1_61_0/libs/range/doc/html/range/reference/adaptors/introduction.html] | |||
* replaced own children list implementation from SPObject with boost intrusive list | |||
* added tests for new children list | |||
* replaced parameters in some functions (Selection with ObjectSet) | |||
* improved spray tool (there is no need to use selection now) | |||
===Problems=== | ===Problems=== | ||
The main and not solved problem at the same time is a segmentation fault occurring when range functions are used. For example: if you declare range as follows: | |||
typedef boost::any_range< | |||
XML::Node*, | |||
boost::bidirectional_traversal_tag, | |||
XML::Node* const&, | |||
std::ptrdiff_t> XMLNodeRange; | |||
struct is_item { | |||
bool operator()(SPObject* obj) { | |||
return SP_IS_ITEM(obj); | |||
} | |||
}; | |||
struct object_to_node { | |||
typedef XML::Node* result_type; | |||
XML::Node* operator()(SPObject* obj) const { | |||
return obj->getRepr(); | |||
} | |||
}; | |||
and then call following function: | |||
XMLNodeRange ObjectSet::xmlNodes() { | |||
return XMLNodeRange(container.get<random_access>() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())); | |||
} | |||
the objects inside the range are invalid and cause segmantation fault, but if you declare XMLNodeRange like below: | |||
typedef decltype(MultiIndexContainer().get<random_access>() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; | |||
everything works. | |||
===Examples=== | ===Examples=== |
Revision as of 10:10, 23 August 2016
This page contains information about "Better data structure for selections" implemented by Adrian Boguszewski. The mentor is Krzysztof Kosiński.
The code is avaiable here: [1]. It has been merged into trunk in rev. 15047.
Project
Goal
This project would involve implementing an Inkscape::ObjectSet
object that would serve as a base for Inkscape::Selection
. The internal data structure should support fast lookup (checking whether a given object belongs to the set) and preserve the order of insertion (so that we can still determine which object was selected first or last). Internally, ObjectSet
can be based on a Boost multi-index container with a list index and a hash index.
Implementation
Following work has been done:
- created ObjectSet class to be a base class for Selection - ObjectSet has a multi_index_container from Boost [2] instead many containers like vectors, lists and sets
- created appropiate tests for this class in GoogleTest framework
- replaced some functions returning vector to return range [3]
- replaced own children list implementation from SPObject with boost intrusive list
- added tests for new children list
- replaced parameters in some functions (Selection with ObjectSet)
- improved spray tool (there is no need to use selection now)
Problems
The main and not solved problem at the same time is a segmentation fault occurring when range functions are used. For example: if you declare range as follows:
typedef boost::any_range< XML::Node*, boost::bidirectional_traversal_tag, XML::Node* const&, std::ptrdiff_t> XMLNodeRange; struct is_item { bool operator()(SPObject* obj) { return SP_IS_ITEM(obj); } }; struct object_to_node { typedef XML::Node* result_type; XML::Node* operator()(SPObject* obj) const { return obj->getRepr(); } };
and then call following function:
XMLNodeRange ObjectSet::xmlNodes() { return XMLNodeRange(container.get<random_access>() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())); }
the objects inside the range are invalid and cause segmantation fault, but if you declare XMLNodeRange like below:
typedef decltype(MultiIndexContainer().get<random_access>() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange;
everything works.