라이브러리
[PHP] DsSet::count - 세트의 값 개수를 반환합니다.
PHP 에서 DsSet::count는 DsSet (Disjoint-set) 클래스의 메소드입니다. Disjoint-set은 Union-Find 알고리즘을 구현한 자료구조입니다. 이 자료구조는 여러 개의 분리된 집합을 관리할 때 유용합니다.
DsSet::count는 현재 집합에 포함된 원소의 수를 반환합니다.
예제
#hostingforum.kr
php
use function SplDoublyLinkedListpush;
use function SplDoublyLinkedListunshift;
use function SplDoublyLinkedListcount;
use function SplDoublyLinkedListcurrent;
use function SplDoublyLinkedList
ewind;
use function SplDoublyLinkedListkey;
class Main {
public function main() {
// DsSet 인스턴스 생성
$ds = new SplObjectStorage();
// 원소 추가
$obj1 = new stdClass();
$obj2 = new stdClass();
$obj3 = new stdClass();
$ds->attach($obj1);
$ds->attach($obj2);
$ds->attach($obj3);
// 원소 수 확인
echo "원소 수 : " . $ds->count() . "
";
// 원소 제거
$ds->detach($obj2);
// 원소 수 확인
echo "원소 수 : " . $ds->count() . "
";
}
}
$main = new Main();
$main->main();
위 예제에서, DsSet 인스턴스를 생성하고 원소를 추가합니다. 그 후 원소 수를 확인하고, 원소를 제거한 후 다시 원소 수를 확인합니다.
결과
#hostingforum.kr
원소 수 : 3
원소 수 : 2
사용 방법
DsSet::count를 사용하려면, 먼저 DsSet 인스턴스를 생성하고 원소를 추가해야 합니다. 그 후, count() 메소드를 호출하여 원소 수를 확인할 수 있습니다.
참고
- [SplObjectStorage](https://www.php.net/manual/en/class.splobjectstorage.php)
- [DsSet](https://www.php.net/manual/en/class.spldoublylinkedlist.php)
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.