123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- namespace Pathfinding.Util {
-
- public static class Memory {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static void MemSet<T>(T[] array, T value, int byteSize) where T : struct {
- if (array == null) {
- throw new ArgumentNullException("array");
- }
- int block = 32, index = 0;
- int length = Math.Min(block, array.Length);
-
- while (index < length) {
- array[index] = value;
- index++;
- }
- length = array.Length;
- while (index < length) {
- Buffer.BlockCopy(array, 0, array, index*byteSize, Math.Min(block, length-index)*byteSize);
- index += block;
- block *= 2;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static void MemSet<T>(T[] array, T value, int totalSize, int byteSize) where T : struct {
- if (array == null) {
- throw new ArgumentNullException("array");
- }
- int block = 32, index = 0;
- int length = Math.Min(block, totalSize);
-
- while (index < length) {
- array[index] = value;
- index++;
- }
- length = totalSize;
- while (index < length) {
- Buffer.BlockCopy(array, 0, array, index*byteSize, Math.Min(block, totalSize-index)*byteSize);
- index += block;
- block *= 2;
- }
- }
-
-
-
-
- public static T[] ShrinkArray<T>(T[] arr, int newLength) {
- newLength = Math.Min(newLength, arr.Length);
- var shrunkArr = new T[newLength];
- Array.Copy(arr, shrunkArr, newLength);
- return shrunkArr;
- }
-
- public static void Swap<T>(ref T a, ref T b) {
- T tmp = a;
- a = b;
- b = tmp;
- }
- }
- }
|