Skip to content

[iss-45] OrdSetsAndMaps#53

Merged
Kalashnikovni merged 29 commits into
sb-graph-devfrom
iss-45-ordmultidimsets
Nov 3, 2025
Merged

[iss-45] OrdSetsAndMaps#53
Kalashnikovni merged 29 commits into
sb-graph-devfrom
iss-45-ordmultidimsets

Conversation

@LucasCavagna

Copy link
Copy Markdown
Collaborator

I decided to implement a new version for all ordered set operations. I used linked lists and different conditions to minimize the number of operations in the intersection process, supporting sets with multiple dimensions and variable steps. Then, I wrote a new version for union, difference, minus, and complement operations to also support multiple dimensions and variable steps.

@LucasCavagna LucasCavagna added the enhancement New feature or request label Mar 26, 2025
@LucasCavagna LucasCavagna added this to the SB-Graph 4.0.0 milestone Mar 26, 2025
@LucasCavagna LucasCavagna self-assigned this Mar 26, 2025
@LucasCavagna LucasCavagna linked an issue Mar 26, 2025 that may be closed by this pull request
@Kalashnikovni Kalashnikovni moved this from To do to In progress in SB-Graph library issue tracker. Mar 26, 2025
@LucasCavagna

Copy link
Copy Markdown
Collaborator Author

Commit from Apr 10, 2025

MODIFICATIONS:

Ordered intersection has been modified — not optimal yet.

interForComl has been added — not the final version.

Ordered complement has been modified — still not final.

Multi-dimensional tests have been added to set_perf.

COMMENTS: The changes to the ordered complement have resulted in improved performance during the tests — approximately 5X faster than the previous implementation.

@LucasCavagna

Copy link
Copy Markdown
Collaborator Author

Commit from Apr 16, 2025

MODIFICATIONS:

The ordered intersection has been updated — this is supposed to be the final version.

interForComl has been modified — we removed unnecessary intersections.

The ordered complement has been updated — almost final version. In the end, there's no need to use the Boost library or perform sorting, either here or in the intersection.

Multi-dimensional tests have been added to set_perf — specifically those that test the conditions added to interForComl.

COMMENTS:
The changes to the ordered complement have led to improved performance during testing — approximately 2X faster than the previous implementation.

@LucasCavagna

Copy link
Copy Markdown
Collaborator Author

Commit from Apr 23, 2025

MODIFICATIONS:

All operations for ordered pwmaps have been implemented except for: reduce, minMap, minAdj, and compact — these are not final versions yet.

The emplaceHint function was added. It inserts a map element into an ordered pwmap in an ordered manner based on a given hint — it attempts to place the element linearly starting from the hint.

COMMENTS:
Operations on ordered pwmaps generally perform as well as or better than those on unordered pwmaps. However, it is only due to the image of the maps that certain operations—like inverse—end up being more costly.

@LucasCavagna

Copy link
Copy Markdown
Collaborator Author

Commit from May 12, 2025

MODIFICATIONS:

Minimal updates applied to orderedSet operations.

Special cases added to enhance behavior in certain operations.

Refactored interForCompl and intersection to separate the search criterion from the search starting point selection.

Variable names updated to be more representative and improve code clarity.

COMMENTS:
These changes are minor and do not significantly impact the performance of operations on orderedSets.

@LucasCavagna

Copy link
Copy Markdown
Collaborator Author

Commit from Jun 8, 2025

MODIFICATIONS:

A bug in the synthetic test cases that caused a segmentation fault was fixed.

COMMENTS:

The current implementation of minimum and maximum perimeter recalculates each time they are needed; it would be good to avoid this without negatively affecting the maps implementation when they are unordered.

Comment thread sbg/natural.cpp
Comment thread sbg/set.hpp
@Kalashnikovni

Copy link
Copy Markdown
Collaborator

I suggest giving English names to all variables and functions to keep the same style for all the project.

Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.hpp
Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
auto liPrev = indices.before_begin();
auto liCurr = indices.begin();

bool doInt = (!(elementMax.menorThan(mdi.minElem())) && !(mdi.maxElem().menorThan(elementMin)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 1163 Is the left side of the && necessary? We check that condition while advancing pos in line 1140.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was resolved with doInt auxiliary function, but

Comment thread sbg/map.cpp Outdated


Map::~Map() {}
Map::Map(const SetAF &fact) : fact_(fact), dom_(fact.createSet()) {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the writing style for all Map constructors.

@LucasCavagna

Copy link
Copy Markdown
Collaborator Author

Commit from Jun 12, 2025

MODIFICATIONS:

All changes committed are based on the previous comments.

Some auxiliary functions have been added to set.cpp for OrderedSets.

COMMENTS:

There is a conflict with some files. I suppose this is because Git is comparing the branches in preparation for a possible merge.

@Kalashnikovni

Kalashnikovni commented Jun 18, 2025

Copy link
Copy Markdown
Collaborator

Changes in pw_map.* are missing because we are getting errors while building saying that menorThan is non-existent now.

@Kalashnikovni

Copy link
Copy Markdown
Collaborator

In general we have used camel case for function names, and for variables underscores:

void someFunction() {
  int my_variable = 10;
  return x*my_variable;
}

Comment thread sbg/multidim_inter.cpp
if (i.isEmpty())
intervals_ = InterVector();
{
if (i.isEmpty()){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's silly, but braces are not necessary.

Comment thread sbg/set.cpp Outdated
Comment thread sbg/set.cpp Outdated
Comment thread sbg/pw_map.cpp Outdated

bool PWMap::operator==(const PWMap &other) const

bool mapEntryComp(const MapEntry &mpe1, const MapEntry &mpe2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can define bool operator<(const MapEntry &mpe1, const MapEntry &mpe2) instead of mapEntryComp?

Comment thread sbg/pw_map.cpp Outdated
{
if (!m.dom().isEmpty()){
MapEntry mpe = createMapEntry(m);
if (pieces_.empty() || pieces_.back().second.first < mpe.second.first)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mapEntryComp instead of pieces_.back().second.first < mpe.second.first.

Comment thread sbg/pw_map.cpp Outdated
Map resComb = fact_.createMap(om.dom(), om.exp());

if (doInt(osp, tsp)){
Set oDom = om.dom(), new_dom = oDom.difference(dom());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dom() can be calculated out of the loop.

Comment thread sbg/pw_map.cpp Outdated
{
return delegate_->filterMap(f);
OrdPWMap res(fact_);
if (subdom.isEmpty())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in firstInv: if (isEmpty() || subdom.isEmpty()) can be used.

Comment thread sbg/pw_map.cpp Outdated
Interval all(0, 1, Inf);
Set univ = fact_.createSet(SetPiece(arity(), all));
OrdPWMapCRef othr = static_cast<OrdPWMapCRef>(other);
processMapsOrd(othr,univ, static_cast<OrdPWMapRef>(*res) , &OrdPWMap::processMinus,true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the purpose of the Set argument of processMapsOrd is to return a value (for example, like in equalImage), univ here should not be passed as argument.
Then, in minAdjMap is used to keep a register for visited values in the domain. I think that is better to modify the function processMapsOrd to take two Sets as arguments: one for input and the other for output.

Comment thread sbg/pw_map.cpp Outdated
unsigned int OrdPWMap::emplaceHint(const Map &m ,unsigned int hint)
{
return delegate_->operator+(*other.delegate_);
auto end = pieces_.end();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if m.dom().isEmpty() before inserting the element in the pw. This way in other functions:

if (!m.dom().isEmpty())
  emplaceHint(...);

can be directly substituted by:

emplaceHint(...);

Comment thread sbg/pw_map.cpp Outdated
for (const MapEntry &mpe : pieces_){
const Map &inv = mpe.first.minInv();
if(!inv.dom().isEmpty())
res.pieces_.emplace_back(createMapEntry(inv));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use OrdPWMap::emplaceBack.

@Kalashnikovni Kalashnikovni merged commit 0b9a099 into sb-graph-dev Nov 3, 2025
2 checks passed
@Kalashnikovni Kalashnikovni moved this from In progress to Done in SB-Graph library issue tracker. Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

OrdMultiDimSets

2 participants