Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Conversation

@weihanglo
Copy link
Owner

@weihanglo weihanglo commented Jan 12, 2019

Close #20

  • Revise API doc of HashSet.
  • Remove unnecessary struct declaration; use move closure to avoid lifetime issues.
  • Implement is_superset, is_subset and is_disjoint.
  • Implement PartialOrd.
  • Add test cases to ensure the properties of empty set.

I've continue doing on your previous work. Please review these code and documentation. You can read the tutorial directly from here.

@weihanglo weihanglo requested a review from choznerol January 12, 2019 06:15
@weihanglo weihanglo changed the title Hashset Revise Hashset impl and doc Jan 12, 2019
Copy link
Contributor

@choznerol choznerol left a comment

Choose a reason for hiding this comment

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

👍👍👍👍👍


let subset: HashSet<_> = ["cat"].iter().cloned().collect();
assert_eq!(set.partial_cmp(&subset), Some(Ordering::Greater));
assert_eq!(&set > &subset, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

怎麼感覺這邊漏兩個 XD

assert_eq!(&set >= &subset, true);
assert_eq!(&set <= &subset, false);

Copy link
Owner Author

Choose a reason for hiding this comment

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

因為 line 770 已經闡明一切
(反正都一樣跑 partial_cmp XD)

與相等關係相同,Rust 的排序關係同樣有理論依據,`Ord` 是數學上的 [Total order][wiki-total-ord],符合反對稱性、傳遞性,以及 [connex relation][wiki-connex-relation];而 `ParitalOrd` 則接近數學上的 partial order,Rust 的文件中描述該 trait 須符合反對稱性與傳遞性。
> Connex relation:在集合 X 下,所有 (x, y) pair 都會符合 x ∼ y 或 y ∼ x 的關係。在排序關係上,意指不是 x ≥ y 就是 y ≥ x。
Copy link
Contributor

Choose a reason for hiding this comment

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

不是 x ≥ y 就是 y ≥ x

不太確定可能是我理解錯> < 不過這邊是要說「 不是 x > y 就是 y > x 」嗎,因為 x y 相等時這不是就會同時發生嗎?

Copy link
Owner Author

Choose a reason for hiding this comment

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

以白話文來說,connex relation 要表達的是在集合 X 下所有元素都可以相互比較,必定有一邊關係成立,不論 x 是否等於 y。定義如下:

∀x∀y (x ∈ X ∧ y ∈ X) ⇒(xRy ∨ yRx )

把「大於等於」抽象為「全序關係」,應該會比較好理解。

Copy link
Contributor

Choose a reason for hiding this comment

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

哦哦好像有點懂了~ xRy ﹀ yRxxRyyRx 至少有一個成立,所以你的意思應該是 x ≧ yy ≧ x 至少有一個成立?或是「如果 x 跟 y 的大於等於『關係』 x ≧ y 不成立, y 跟 x 的大於等於『關係』 y ≧ x 就會成立」(而不是 either ... or)

Co-Authored-By: choznerol <[email protected]>

Co-Authored-By: weihanglo <[email protected]>
@weihanglo weihanglo merged commit 0f74333 into master Jan 13, 2019
@weihanglo weihanglo deleted the hashset branch January 13, 2019 13:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants