/*
Copyright 1999 CERN - European Organization for Nuclear Research.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
is hereby granted without fee, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation.
CERN makes no representations about the suitability of this software for any purpose.
It is provided "as is" without expressed or implied warranty.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DiscoveryLogic.Common.Numeric
{
public class Arrays : System.Object
{
/// <summary> Ensures that the specified array cannot hold more than <tt>maxCapacity</tt> elements.
/// An application can use this operation to minimize array storage.
/// <p>
/// Returns the identical array if <tt>array.length <= maxCapacity</tt>.
/// Otherwise, returns a new array with a length of <tt>maxCapacity</tt>
/// containing the first <tt>maxCapacity</tt> elements of <tt>array</tt>.
///
/// </summary>
/// <param name="maxCapacity"> the desired maximum capacity.
/// </param>
public static float[] trimToCapacity(float[] array, int maxCapacity)
{
if (array.Length > maxCapacity)
{
float[] oldArray = array;
array = new float[maxCapacity];
Array.Copy(oldArray, 0, array, 0, maxCapacity);
}
return array;
}
}
}
|