babylon.smartArray.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var SmartArray = (function () {
  4. function SmartArray(capacity) {
  5. this.length = 0;
  6. this.data = new Array(capacity);
  7. }
  8. SmartArray.prototype.push = function (value) {
  9. this.data[this.length++] = value;
  10. if (this.length > this.data.length) {
  11. this.data.length *= 2;
  12. }
  13. };
  14. SmartArray.prototype.pushNoDuplicate = function (value) {
  15. if (this.indexOf(value) > -1) {
  16. return;
  17. }
  18. this.push(value);
  19. };
  20. SmartArray.prototype.sort = function (compareFn) {
  21. this.data.sort(compareFn);
  22. };
  23. SmartArray.prototype.reset = function () {
  24. this.length = 0;
  25. };
  26. SmartArray.prototype.concat = function (array) {
  27. if (array.length === 0) {
  28. return;
  29. }
  30. if (this.length + array.length > this.data.length) {
  31. this.data.length = (this.length + array.length) * 2;
  32. }
  33. for (var index = 0; index < array.length; index++) {
  34. this.data[this.length++] = (array.data || array)[index];
  35. }
  36. };
  37. SmartArray.prototype.concatWithNoDuplicate = function (array) {
  38. if (array.length === 0) {
  39. return;
  40. }
  41. if (this.length + array.length > this.data.length) {
  42. this.data.length = (this.length + array.length) * 2;
  43. }
  44. for (var index = 0; index < array.length; index++) {
  45. var item = (array.data || array)[index];
  46. var pos = this.data.indexOf(item);
  47. if (pos === -1 || pos >= this.length) {
  48. this.data[this.length++] = item;
  49. }
  50. }
  51. };
  52. SmartArray.prototype.indexOf = function (value) {
  53. var position = this.data.indexOf(value);
  54. if (position >= this.length) {
  55. return -1;
  56. }
  57. return position;
  58. };
  59. return SmartArray;
  60. })();
  61. BABYLON.SmartArray = SmartArray;
  62. })(BABYLON || (BABYLON = {}));
  63. //# sourceMappingURL=babylon.smartArray.js.map