Class CollectionUtils
- Namespace
- Framework.Common.Collections
- Assembly
- Assembly-CSharp.dll
컬렉션 관련 순수 static 유틸. Unity 의존 없음.
public static class CollectionUtils
- Inheritance
-
objectCollectionUtils
Methods
RandomPick<T>(IList<T>, Random)
리스트에서 무작위 요소 반환.
public static T RandomPick<T>(IList<T> list, Random random = null)
Parameters
listIList<T>대상 리스트.
randomRandom사용할 랜덤 인스턴스. null이면 기본 랜덤 사용.
Returns
- T
무작위 요소. 리스트가 null이거나 비어있으면 default.
Type Parameters
T요소 타입.
RemoveSwapBack<T>(IList<T>, int)
O(1) 삭제. 마지막 요소와 교체 후 제거. 순서 비보장.
public static void RemoveSwapBack<T>(IList<T> list, int index)
Parameters
listIList<T>대상 리스트.
indexint삭제할 인덱스.
Type Parameters
T요소 타입.
Shuffle<T>(IList<T>, Random)
Fisher-Yates 알고리즘으로 리스트를 제자리(in-place) 셔플.
public static void Shuffle<T>(IList<T> list, Random random = null)
Parameters
listIList<T>셔플할 리스트.
randomRandom재현 가능성이 필요하면 고정 Seed의 System.Random을 전달. null이면 기본 랜덤 사용.
Type Parameters
T리스트 요소 타입.
Examples
var list = new List<int> { 1, 2, 3, 4, 5 };
CollectionUtils.Shuffle(list);