mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2025-12-13 15:52:03 +07:00
AssignTo for IsoList's
This commit is contained in:
@@ -21,12 +21,6 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
public int this[T item] {
|
||||
get {
|
||||
return _dict[item];
|
||||
}
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get {
|
||||
return _list.Count;
|
||||
@@ -54,7 +48,6 @@ namespace IsoTools.Internal {
|
||||
if ( index != _list.Count ) {
|
||||
_dict[_list[index]] = index;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -74,5 +67,13 @@ namespace IsoTools.Internal {
|
||||
_list.Clear();
|
||||
_dict.Clear();
|
||||
}
|
||||
|
||||
public void AssignTo(List<T> list) {
|
||||
_list.AssignTo(list);
|
||||
}
|
||||
|
||||
public void AssignTo(IsoList<T> list) {
|
||||
_list.AssignTo(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IsoTools.Internal {
|
||||
public class IsoList<T> {
|
||||
@@ -103,5 +104,32 @@ namespace IsoTools.Internal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AssignTo(List<T> list) {
|
||||
list.Clear();
|
||||
if ( list.Capacity < Count ) {
|
||||
list.Capacity = Count * 2;
|
||||
}
|
||||
for ( int i = 0, e = Count; i < e; ++i ) {
|
||||
list.Add(this[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void AssignTo(IsoList<T> list) {
|
||||
if ( list._data.Length < _size ) {
|
||||
var new_data = new T[_size * 2];
|
||||
Array.Copy(_data, new_data, _size);
|
||||
list._data = new_data;
|
||||
list._size = _size;
|
||||
} else {
|
||||
if ( _size < list._size ) {
|
||||
Array.Clear(list._data, _size, list._size - _size);
|
||||
}
|
||||
if ( _size > 0 ) {
|
||||
Array.Copy(_data, list._data, _size);
|
||||
}
|
||||
list._size = _size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user