patch for archiving.

Chris Dams chrisd at sci.kun.nl
Wed Apr 23 12:03:04 CEST 2003


Hello,

I found out that during archiving for every expression that is archived
all nodes of the archive are searched to see if the expression is already
there. This takes way too long for large archives. The solution is to have
a map that stores where in the archive expressions are stored. A patch is
included.

All the best,
Chris Dams
-------------- next part --------------
===================================================================
RCS file: /home/cvs/GiNaC/ginac/archive.cpp,v
retrieving revision 1.19.2.3
diff -r1.19.2.3 archive.cpp
53,59c53,60
< 	// Search for node in nodes vector
< 	std::vector<archive_node>::const_iterator i = nodes.begin(), iend = nodes.end();
< 	archive_node_id id = 0;
< 	while (i != iend) {
< 		if (i->has_same_ex_as(n))
< 			return id;
< 		i++; id++;
---
> 	// Look if expression is known to be in some node already.
> 	if(n.has_ex())
> 	{	mapit i=exprtable.find(n.get_ex());
> 		if(i != exprtable.end())
> 			return i->second;
> 		nodes.push_back(n);
> 		exprtable[n.get_ex()]=nodes.size()-1;
> 		return nodes.size()-1;
64c65
< 	return id;
---
> 	return nodes.size()-1;
361a363,375
> /** Check if node is known to store an unarchived exression */
> bool archive_node::has_ex() const
> {
> 	return has_expression;
> }
> 
> /** Return unarchived version of expression stored in this node */
> ex archive_node::get_ex() const
> {
> 	return e;
> }
> 
> 
546a561
> 	exprtable.clear();
Index: archive.h
===================================================================
RCS file: /home/cvs/GiNaC/ginac/archive.h,v
retrieving revision 1.17.2.3
diff -r1.17.2.3 archive.h
30a31
> #include <map>
123a125,126
> 	bool has_ex() const;
> 	ex get_ex() const;
238a242,245
> 
> 	/** Map of stored expressions to nodes for faster archiving */
> 	typedef std::map<ex,archive_node_id,ex_is_less>::iterator mapit;
> 	mutable std::map<ex,archive_node_id,ex_is_less> exprtable;


More information about the GiNaC-devel mailing list