wasSharp – Diff between revs 1 and 5
?pathlinks?
Rev 1 | Rev 5 | |||
---|---|---|---|---|
Line 18... | Line 18... | |||
18 | /// </summary> |
18 | /// </summary> |
|
19 | /// <typeparam name="T">the array type</typeparam> |
19 | /// <typeparam name="T">the array type</typeparam> |
|
20 | /// <param name="index">a positive or negative index of the element</param> |
20 | /// <param name="index">a positive or negative index of the element</param> |
|
21 | /// <param name="data">the array</param> |
21 | /// <param name="data">the array</param> |
|
22 | /// <return>an array element</return> |
22 | /// <return>an array element</return> |
|
23 | public static T wasGetElementAt<T>(T[] data, int index) |
23 | public static T GetElementAt<T>(T[] data, int index) |
|
24 | { |
24 | { |
|
25 | switch (index < 0) |
25 | switch (index < 0) |
|
26 | { |
26 | { |
|
27 | case true: |
27 | case true: |
|
28 | return data[((index%data.Length) + data.Length)%data.Length]; |
28 | return data[((index%data.Length) + data.Length)%data.Length]; |
|
Line 40... | Line 40... | |||
40 | /// <typeparam name="T">the array type</typeparam> |
40 | /// <typeparam name="T">the array type</typeparam> |
|
41 | /// <param name="data">the array</param> |
41 | /// <param name="data">the array</param> |
|
42 | /// <param name="start">the start index</param> |
42 | /// <param name="start">the start index</param> |
|
43 | /// <param name="stop">the stop index (-1 denotes the end)</param> |
43 | /// <param name="stop">the stop index (-1 denotes the end)</param> |
|
44 | /// <returns>the array slice between start and stop</returns> |
44 | /// <returns>the array slice between start and stop</returns> |
|
45 | public static T[] wasGetSubArray<T>(T[] data, int start, int stop) |
45 | public static T[] GetSubArray<T>(T[] data, int start, int stop) |
|
46 | { |
46 | { |
|
47 | if (stop.Equals(-1)) |
47 | if (stop.Equals(-1)) |
|
48 | stop = data.Length - 1; |
48 | stop = data.Length - 1; |
|
49 | T[] result = new T[stop - start + 1]; |
49 | T[] result = new T[stop - start + 1]; |
|
50 | Array.Copy(data, start, result, 0, stop - start + 1); |
50 | Array.Copy(data, start, result, 0, stop - start + 1); |
|
Line 60... | Line 60... | |||
60 | /// <typeparam name="T">the array type</typeparam> |
60 | /// <typeparam name="T">the array type</typeparam> |
|
61 | /// <param name="data">the array</param> |
61 | /// <param name="data">the array</param> |
|
62 | /// <param name="start">the start index</param> |
62 | /// <param name="start">the start index</param> |
|
63 | /// <param name="stop">the stop index (-1 denotes the end)</param> |
63 | /// <param name="stop">the stop index (-1 denotes the end)</param> |
|
64 | /// <returns>the array without elements between start and stop</returns> |
64 | /// <returns>the array without elements between start and stop</returns> |
|
65 | public static T[] wasDeleteSubArray<T>(T[] data, int start, int stop) |
65 | public static T[] DeleteSubArray<T>(T[] data, int start, int stop) |
|
66 | { |
66 | { |
|
67 | if (stop.Equals(-1)) |
67 | if (stop.Equals(-1)) |
|
68 | stop = data.Length - 1; |
68 | stop = data.Length - 1; |
|
69 | T[] result = new T[data.Length - (stop - start) - 1]; |
69 | T[] result = new T[data.Length - (stop - start) - 1]; |
|
70 | Array.Copy(data, 0, result, 0, start); |
70 | Array.Copy(data, 0, result, 0, start); |
|
Line 79... | Line 79... | |||
79 | /// Concatenate multiple arrays. |
79 | /// Concatenate multiple arrays. |
|
80 | /// </summary> |
80 | /// </summary> |
|
81 | /// <typeparam name="T">the array type</typeparam> |
81 | /// <typeparam name="T">the array type</typeparam> |
|
82 | /// <param name="arrays">multiple arrays</param> |
82 | /// <param name="arrays">multiple arrays</param> |
|
83 | /// <returns>a flat array with all arrays concatenated</returns> |
83 | /// <returns>a flat array with all arrays concatenated</returns> |
|
84 | public static T[] wasConcatenateArrays<T>(params T[][] arrays) |
84 | public static T[] ConcatenateArrays<T>(params T[][] arrays) |
|
85 | { |
85 | { |
|
86 | int resultLength = 0; |
86 | int resultLength = 0; |
|
87 | foreach (T[] o in arrays) |
87 | foreach (T[] o in arrays) |
|
88 | { |
88 | { |
|
89 | resultLength += o.Length; |
89 | resultLength += o.Length; |
|
Line 106... | Line 106... | |||
106 | /// </summary> |
106 | /// </summary> |
|
107 | /// <typeparam name="T">the array type</typeparam> |
107 | /// <typeparam name="T">the array type</typeparam> |
|
108 | /// <param name="input">the array</param> |
108 | /// <param name="input">the array</param> |
|
109 | /// <param name="times">the number of times to permute</param> |
109 | /// <param name="times">the number of times to permute</param> |
|
110 | /// <returns>the array with the elements permuted</returns> |
110 | /// <returns>the array with the elements permuted</returns> |
|
111 | public static T[] wasReversePermuteArrayElements<T>(T[] input, int times) |
111 | public static T[] ReversePermuteArrayElements<T>(T[] input, int times) |
|
112 | { |
112 | { |
|
113 | if (times.Equals(0)) return input; |
113 | if (times.Equals(0)) return input; |
|
114 | T[] slice = new T[input.Length]; |
114 | T[] slice = new T[input.Length]; |
|
115 | Array.Copy(input, 1, slice, 0, input.Length - 1); |
115 | Array.Copy(input, 1, slice, 0, input.Length - 1); |
|
116 | Array.Copy(input, 0, slice, input.Length - 1, 1); |
116 | Array.Copy(input, 0, slice, input.Length - 1, 1); |
|
117 | return wasReversePermuteArrayElements(slice, --times); |
117 | return ReversePermuteArrayElements(slice, --times); |
|
118 | } |
118 | } |
|
Line 119... | Line 119... | |||
119 | |
119 | |
|
120 | /////////////////////////////////////////////////////////////////////////// |
120 | /////////////////////////////////////////////////////////////////////////// |
|
121 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
121 | // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
|
Line 125... | Line 125... | |||
125 | /// </summary> |
125 | /// </summary> |
|
126 | /// <typeparam name="T">the array type</typeparam> |
126 | /// <typeparam name="T">the array type</typeparam> |
|
127 | /// <param name="input">the array</param> |
127 | /// <param name="input">the array</param> |
|
128 | /// <param name="times">the number of times to permute</param> |
128 | /// <param name="times">the number of times to permute</param> |
|
129 | /// <returns>the array with the elements permuted</returns> |
129 | /// <returns>the array with the elements permuted</returns> |
|
130 | public static T[] wasForwardPermuteArrayElements<T>(T[] input, int times) |
130 | public static T[] ForwardPermuteArrayElements<T>(T[] input, int times) |
|
131 | { |
131 | { |
|
132 | if (times.Equals(0)) return input; |
132 | if (times.Equals(0)) return input; |
|
133 | T[] slice = new T[input.Length]; |
133 | T[] slice = new T[input.Length]; |
|
134 | Array.Copy(input, input.Length - 1, slice, 0, 1); |
134 | Array.Copy(input, input.Length - 1, slice, 0, 1); |
|
135 | Array.Copy(input, 0, slice, 1, input.Length - 1); |
135 | Array.Copy(input, 0, slice, 1, input.Length - 1); |
|
136 | return wasForwardPermuteArrayElements(slice, --times); |
136 | return ForwardPermuteArrayElements(slice, --times); |
|
137 | } |
137 | } |
|
138 | } |
138 | } |
|
139 | } |
139 | } |
|
140 | |
140 | |