Skip to content

Commit

Permalink
Version 2.1, better aggregation performance, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Smith committed Apr 27, 2015
1 parent 4871b2c commit d477a2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function() {
```

Where dataType is: 'Int8' || 'Int16' || 'Int32' || 'Uint8' || 'Uint16' || 'Uint32' || 'Float32' || 'Float64'
Where dataType is: 'Int8' || 'Int16' || 'Int32' || 'Uint8' || 'Uint8Clamped' || 'Uint16' || 'Uint32' || 'Float32' || 'Float64'


# Debugging
Expand Down
28 changes: 20 additions & 8 deletions hamsters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/*globals self,Worker,Blob,rtn*/
/*jslint vars:true, devel:true, browser:true, evil:true*/
//** End JS Lint Settings **

/*
* Title: WebHamsters
* Description: Javascript library to add multi-threading support to javascript by exploiting concurrent web workers
Expand All @@ -12,7 +13,7 @@
*/
//** Start Setup **
var hamsters = {
version: '2.0',
version: '2.1',
debug: false,
maxThreads: Math.ceil((navigator.hardwareConcurrency || 1) * 1.25),
tools: {},
Expand Down Expand Up @@ -83,7 +84,7 @@ hamsters.runtime.wakeUp = function() {
*/
hamsters.tools.splitArray = function(array, n) {
if(array.length && !array.slice) {
array = hamsters.runtime.convertArray(array);
array = hamsters.runtime.normalizeArray(array);
}
var tasks = [];
var i = 0;
Expand Down Expand Up @@ -524,11 +525,7 @@ hamsters.runtime.wakeUp = function() {
return input;
}
if(dataType) {
var out = [];
for (var i = 0, len = input.length; i < len; i++) {
out.push(hamsters.runtime.convertArray(input[i]));
}
input = out;
return hamsters.runtime.aggregateTypedArrays(input, dataType);
}
var output = [];
output = input.reduce(function(a, b) {
Expand Down Expand Up @@ -673,13 +670,28 @@ hamsters.runtime.wakeUp = function() {
* @constructor
* @param {object} input - typedArray input
*/
hamsters.runtime.convertArray = function(input) {
hamsters.runtime.normalizeArray = function(input) {
var arr = [];
for (var n = 0, len = input.length; n < len; n++) {
arr.push(input[n]);
}
return arr;
};

hamsters.runtime.aggregateTypedArrays = function(input, dataType) {
var output;
var length = 0;
var offset = 0;
for (var i = 0, len = input.length; i < len; i++) {
length += input[i].length;
}
output = hamsters.runtime.processDataType(dataType, length);
for (var n = 0, len2 = input.length; n < len2; n++) {
output.set(input[n], offset);
offset += input[n].length;
}
return output;
};
/**
* @function processDataType
* @description: Converts array buffer or normal array into a typed array
Expand Down
Loading

0 comments on commit d477a2f

Please sign in to comment.