Skip to content

Conversation

@kushti
Copy link
Member

@kushti kushti commented Jun 12, 2024

In this PR, new collection methods got introduced:

  • reverse
  • distinct
  • startsWith
  • endsWith
  • get

close #1004

@kushti kushti added this to the 6.0.0 milestone Jun 12, 2024
@kushti kushti self-assigned this Jun 12, 2024
@kushti kushti requested a review from aslesarenko September 27, 2024 12:15
Copy link
Member

@aslesarenko aslesarenko left a comment

Choose a reason for hiding this comment

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

Approved, but please address the comments.

* @return the element at the given index
* @throws ArrayIndexOutOfBoundsException if `i < 0` or `length <= i`
*/
def get(i: Int): Option[A] = {
Copy link
Member

Choose a reason for hiding this comment

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

ScalaDoc doesn't correspond to the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


/** For this collection (x0, ..., xN) and other collection (y0, ..., yM)
* produces a collection ((x0, y0), ..., (xK, yK)) where K = min(N, M) */
def startsWith(ys: Coll[A]): Boolean
Copy link
Member

Choose a reason for hiding this comment

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

ScalaDoc is not correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


/** For this collection (x0, ..., xN) and other collection (y0, ..., yM)
* produces a collection ((x0, y0), ..., (xK, yK)) where K = min(N, M) */
def endsWith(ys: Coll[A]): Boolean
Copy link
Member

Choose a reason for hiding this comment

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

ScalaDoc is not correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


def startsWith(ys: Coll[(L, R)]): Boolean = toArray.startsWith(ys.toArray)

def endsWith(ys: Coll[(L, R)]): Boolean = toArray.endsWith(ys.toArray)
Copy link
Member

Choose a reason for hiding this comment

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

This is simple, but inefficient ((ys.length + 1)*2 allocations) fallback implementation.
In the case when ys has type PairOfCols, it is possible to recursively call into ls and rs, and avoid allocations.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, added tests also

// ======== 6.0 methods below ===========

val ReverseMethod = SMethod(this, "reverse",
SFunc(Array(ThisType), ThisType, paramIVSeq), 30, Zip_CostKind) // todo: costing
Copy link
Member

Choose a reason for hiding this comment

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

Suggest to declare the descriptor by just cloning from Append (Zip is too small).

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

}

val DistinctMethod = SMethod(this, "distinct",
SFunc(Array(ThisType), ThisType, paramIVSeq), 31, Zip_CostKind) // todo: costing
Copy link
Member

Choose a reason for hiding this comment

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

The cost of distinct is larger then zip or Append, probably by a factor of 2.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Seq(
Coll(1, 2) -> Expected(ExpectedResult(Success(Coll(1, 2)), None)),
Coll(1, 1, 2) -> Expected(ExpectedResult(Success(Coll(1, 2)), None)),
Coll(1, 2, 2) -> Expected(ExpectedResult(Success(Coll(1, 2)), None)),
Copy link
Member

Choose a reason for hiding this comment

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

Suggest to add a case with unordered collections and many different duplicates.

Copy link
Member Author

Choose a reason for hiding this comment

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

added

(Coll(1, 2, 3), Coll(1, 2)) -> Expected(ExpectedResult(Success(true), None)),
(Coll(1, 2, 3), Coll(1, 2, 3)) -> Expected(ExpectedResult(Success(true), None)),
(Coll(1, 2, 3), Coll(1, 2, 3, 4)) -> Expected(ExpectedResult(Success(false), None)),
(Coll[Int](), Coll[Int]()) -> Expected(ExpectedResult(Success(true), None))
Copy link
Member

Choose a reason for hiding this comment

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

Not covered cases:

  • Coll(1, 2, 3), Coll(1, 2, 4)
  • Coll[Int](1, 2), CollInt

Copy link
Member Author

Choose a reason for hiding this comment

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

added

@kushti kushti merged commit 83ba4a4 into v6.0.0 Oct 7, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants