Set.size will now only set the new size if the value is smaller than the current size, truncating the Set in the process. Values larger than the current size are ignored.

Plus added jsdocs.
This commit is contained in:
Richard Davey 2018-09-28 12:44:55 +01:00
parent c237209bb8
commit 3aef1e8a65

View file

@ -28,7 +28,7 @@ var Class = require('../utils/Class');
* @generic T
* @genericUse {T[]} - [elements]
*
* @param {Array.<*>} [elements] - [description]
* @param {Array.<*>} [elements] - An optional array of elements to insert into this Set.
*/
var Set = new Class({
@ -37,7 +37,7 @@ var Set = new Class({
function Set (elements)
{
/**
* [description]
* The entries of this Set. Stored internally as an array.
*
* @genericUse {T[]} - [$type]
*
@ -58,7 +58,7 @@ var Set = new Class({
},
/**
* [description]
* Inserts the provided value into this Set. If the value is already contained in this Set this method will have no effect.
*
* @method Phaser.Structs.Set#set
* @since 3.0.0
@ -66,7 +66,7 @@ var Set = new Class({
* @genericUse {T} - [value]
* @genericUse {Phaser.Structs.Set.<T>} - [$return]
*
* @param {*} value - [description]
* @param {*} value - The value to insert into this Set.
*
* @return {Phaser.Structs.Set} This Set object.
*/
@ -81,17 +81,18 @@ var Set = new Class({
},
/**
* [description]
* Get an element of this Set which has a property of the specified name, if that property is equal to the specified value.
* If no elements of this Set satisfy the condition then this method will return `null`.
*
* @method Phaser.Structs.Set#get
* @since 3.0.0
*
* @genericUse {T} - [value,$return]
*
* @param {string} property - [description]
* @param {*} value - [description]
* @param {string} property - The property name to check on the elements of this Set.
* @param {*} value - The value to check for.
*
* @return {*} [description]
* @return {*} The first element of this Set that meets the required condition, or `null` if this Set contains no elements that meet the condition.
*/
get: function (property, value)
{
@ -107,14 +108,14 @@ var Set = new Class({
},
/**
* [description]
* Returns an array containing all the values in this Set.
*
* @method Phaser.Structs.Set#getArray
* @since 3.0.0
*
* @genericUse {T[]} - [$return]
*
* @return {Array.<*>} [description]
* @return {Array.<*>} An array containing all the values in this Set.
*/
getArray: function ()
{
@ -122,7 +123,7 @@ var Set = new Class({
},
/**
* [description]
* Removes the given value from this Set if this Set contains that value.
*
* @method Phaser.Structs.Set#delete
* @since 3.0.0
@ -130,7 +131,7 @@ var Set = new Class({
* @genericUse {T} - [value]
* @genericUse {Phaser.Structs.Set.<T>} - [$return]
*
* @param {*} value - [description]
* @param {*} value - The value to remove from the Set.
*
* @return {Phaser.Structs.Set} This Set object.
*/
@ -147,7 +148,7 @@ var Set = new Class({
},
/**
* [description]
* Dumps the contents of this Set to the console via `console.group`.
*
* @method Phaser.Structs.Set#dump
* @since 3.0.0
@ -168,7 +169,8 @@ var Set = new Class({
},
/**
* For when you know this Set will be modified during the iteration.
* Passes each value in this Set to the given callback.
* Use this function when you know this Set will be modified during the iteration, otherwise use `iterate`.
*
* @method Phaser.Structs.Set#each
* @since 3.0.0
@ -176,8 +178,8 @@ var Set = new Class({
* @genericUse {EachSetCallback.<T>} - [callback]
* @genericUse {Phaser.Structs.Set.<T>} - [$return]
*
* @param {EachSetCallback} callback - [description]
* @param {*} callbackScope - [description]
* @param {EachSetCallback} callback - The callback to be invoked and passed each value this Set contains.
* @param {*} callbackScope - The scope of the callback.
*
* @return {Phaser.Structs.Set} This Set object.
*/
@ -212,6 +214,7 @@ var Set = new Class({
},
/**
* Passes each value in this Set to the given callback.
* For when you absolutely know this Set won't be modified during the iteration.
*
* @method Phaser.Structs.Set#iterate
@ -220,8 +223,8 @@ var Set = new Class({
* @genericUse {EachSetCallback.<T>} - [callback]
* @genericUse {Phaser.Structs.Set.<T>} - [$return]
*
* @param {EachSetCallback} callback - [description]
* @param {*} [callbackScope] - [description]
* @param {EachSetCallback} callback - The callback to be invoked and passed each value this Set contains.
* @param {*} callbackScope - The scope of the callback.
*
* @return {Phaser.Structs.Set} This Set object.
*/
@ -255,14 +258,14 @@ var Set = new Class({
},
/**
* [description]
* Goes through each entry in this Set and invokes the given function on them, passing in the arguments.
*
* @method Phaser.Structs.Set#iterateLocal
* @since 3.0.0
*
* @genericUse {Phaser.Structs.Set.<T>} - [$return]
*
* @param {string} callbackKey - [description]
* @param {string} callbackKey - The key of the function to be invoked on each Set entry.
* @param {...*} [args] - Additional arguments that will be passed to the callback, after the child.
*
* @return {Phaser.Structs.Set} This Set object.
@ -290,7 +293,7 @@ var Set = new Class({
},
/**
* [description]
* Clears this Set so that it no longer contains any values.
*
* @method Phaser.Structs.Set#clear
* @since 3.0.0
@ -307,16 +310,16 @@ var Set = new Class({
},
/**
* [description]
* Returns `true` if this Set contains the given value, otherwise returns `false`.
*
* @method Phaser.Structs.Set#contains
* @since 3.0.0
*
* @genericUse {T} - [value]
*
* @param {*} value - [description]
* @param {*} value - The value to check for in this Set.
*
* @return {boolean} [description]
* @return {boolean} `true` if the given value was found in this Set, otherwise `false`.
*/
contains: function (value)
{
@ -324,16 +327,16 @@ var Set = new Class({
},
/**
* [description]
* Returns a new Set containing all values that are either in this Set or in the Set provided as an argument.
*
* @method Phaser.Structs.Set#union
* @since 3.0.0
*
* @genericUse {Phaser.Structs.Set.<T>} - [set,$return]
*
* @param {Phaser.Structs.Set} set - [description]
* @param {Phaser.Structs.Set} set - The Set to perform the union with.
*
* @return {Phaser.Structs.Set} [description]
* @return {Phaser.Structs.Set} A new Set containing all the values in this Set and the Set provided as an argument.
*/
union: function (set)
{
@ -353,16 +356,16 @@ var Set = new Class({
},
/**
* [description]
* Returns a new Set that contains only the values which are in this Set and that are also in the given Set.
*
* @method Phaser.Structs.Set#intersect
* @since 3.0.0
*
* @genericUse {Phaser.Structs.Set.<T>} - [set,$return]
*
* @param {Phaser.Structs.Set} set - [description]
* @param {Phaser.Structs.Set} set - The Set to intersect this set with.
*
* @return {Phaser.Structs.Set} [description]
* @return {Phaser.Structs.Set} The result of the intersection, as a new Set.
*/
intersect: function (set)
{
@ -380,16 +383,16 @@ var Set = new Class({
},
/**
* [description]
* Returns a new Set containing all the values in this Set which are *not* also in the given Set.
*
* @method Phaser.Structs.Set#difference
* @since 3.0.0
*
* @genericUse {Phaser.Structs.Set.<T>} - [set,$return]
*
* @param {Phaser.Structs.Set} set - [description]
* @param {Phaser.Structs.Set} set - The Set to perform the difference with.
*
* @return {Phaser.Structs.Set} [description]
* @return {Phaser.Structs.Set} A new Set containing all the values in this Set that are not also in the Set provided as an argument to this method.
*/
difference: function (set)
{
@ -407,7 +410,9 @@ var Set = new Class({
},
/**
* [description]
* The size of this Set. This is the number of entries within it.
* Changing the size will truncate the Set if the given value is smaller than the current size.
* Increasing the size larger than the current size has no effect.
*
* @name Phaser.Structs.Set#size
* @type {integer}
@ -422,7 +427,14 @@ var Set = new Class({
set: function (value)
{
return this.entries.length = value;
if (value < this.entries.length)
{
return this.entries.length = value;
}
else
{
return this.entries.length;
}
}
}