Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve an AsList method for domains with stored GeneratorsOfDomain #3473

Merged
merged 1 commit into from
Jun 5, 2019

Conversation

ssiccha
Copy link
Contributor

@ssiccha ssiccha commented May 24, 2019

The new method ensures that no copy of GeneratorsOfDomain is created if
GeneratorsOfDomain already is a duplicate free list.

@ssiccha ssiccha added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels May 24, 2019
@ssiccha ssiccha changed the title lib: improve an AsList method for domains with ... Improve an AsList method for domains with stored GeneratorsOfDomain May 24, 2019
@ssiccha
Copy link
Contributor Author

ssiccha commented May 24, 2019

Let's see whether any of the manual tests fail due to new printing of e.g. AsList(Domain([1 .. 3])).

@coveralls
Copy link

coveralls commented May 24, 2019

Coverage Status

Coverage increased (+0.0008%) to 85.169% when pulling eb8f36b on ssiccha:ss/improve-AsList-for-domains into 5d81b55 on gap-system:master.

lib/domain.gi Outdated Show resolved Hide resolved
@ssiccha ssiccha force-pushed the ss/improve-AsList-for-domains branch 2 times, most recently from dcc0a86 to ea98daf Compare May 26, 2019 14:05
@codecov
Copy link

codecov bot commented May 26, 2019

Codecov Report

Merging #3473 into master will decrease coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #3473      +/-   ##
==========================================
- Coverage   85.34%   85.34%   -0.01%     
==========================================
  Files         699      699              
  Lines      346504   346487      -17     
==========================================
- Hits       295733   295715      -18     
- Misses      50771    50772       +1
Impacted Files Coverage Δ
lib/domain.gi 87.93% <100%> (-2.57%) ⬇️
lib/coll.gd 95.09% <0%> (-0.07%) ⬇️
lib/domain.gd 100% <0%> (ø) ⬆️
lib/grp.gi 89.36% <0%> (+0.07%) ⬆️

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

Unfortunately, there is a conflict with master now, due to another PR from you having been merged.

lib/domain.gi Outdated Show resolved Hide resolved
@ssiccha ssiccha force-pushed the ss/improve-AsList-for-domains branch from ea98daf to 168907c Compare May 30, 2019 07:45
@ssiccha
Copy link
Contributor Author

ssiccha commented May 30, 2019

I resolved the merge conflict.

@fingolfin fingolfin self-requested a review May 30, 2019 10:04
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

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

I really would feel better if some more people had a look at this (e.g. @stevelinton @ChrisJefferson ...)

if IsDuplicateFreeList( GeneratorsOfDomain( D ) ) then
return GeneratorsOfDomain( D );
else
return DuplicateFreeList( GeneratorsOfDomain( D ) );
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this some more, I am not really sure anymore whether this is an "improvement", as the description of this PR claims: AsList is an attribute. So we are talking about a one-time cost here. Now, with the old code, we'd just call DuplicateFreeList, which performs an O(n^2) algorithm.
With this "improvement", we instead first run IsDuplicateFreeList, which also is O(n^2). And if it fails, we still run DuplicateFreeList. So while there may be scenarios where this saves something (namely memory, but not performance), there are also scenarios where it results in a slow-down.

Are there any real-world applications that motivate this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I'm completely fine with changing the condition to
HasIsDuplicateFreeList( GeneratorsOfDomain( D ) ) and IsDuplicateFreeList( GeneratorsOfDomain( D ) ).

Copy link
Contributor Author

@ssiccha ssiccha May 30, 2019

Choose a reason for hiding this comment

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

Are there any real-world applications that motivate this change?

I want AsList(Domain([1..3])) to return the range [1..3]. At the moment gap returns the plain list [1,2,3]. As the range [1..3] knows that it is a IsDuplicateFreeList in this situation there should be no reason to copy it and create a new plain list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the condition to
HasIsDuplicateFreeList( GeneratorsOfDomain( D ) ) and IsDuplicateFreeList( GeneratorsOfDomain( D ) )

Copy link
Member

Choose a reason for hiding this comment

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

With HasIsDuplicateFreeList it is of course fine.

... stored GeneratorsOfDomain.

The new version ensures that no copy of GeneratorsOfDomain is created if
GeneratorsOfDomain already is a duplicate free list.

Adds tests for this situation.
@ssiccha ssiccha force-pushed the ss/improve-AsList-for-domains branch from 168907c to eb8f36b Compare May 30, 2019 10:43
Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

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

I don't see any potential harm with making this change as it exists now; there's essentially no overhead to the new check.

if IsDuplicateFreeList( GeneratorsOfDomain( D ) ) then
return GeneratorsOfDomain( D );
else
return DuplicateFreeList( GeneratorsOfDomain( D ) );
Copy link
Member

Choose a reason for hiding this comment

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

With HasIsDuplicateFreeList it is of course fine.

@fingolfin fingolfin merged commit 48612ec into gap-system:master Jun 5, 2019
@ssiccha ssiccha deleted the ss/improve-AsList-for-domains branch August 7, 2019 08:47
@fingolfin fingolfin added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Aug 22, 2019
@olexandr-konovalov olexandr-konovalov added this to the GAP 4.11.0 milestone Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: added PRs introducing changes that have since been mentioned in the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants