Javascript中的ArrayBuffers的3D数组?

时间:2016-05-19 20:17:56

标签: javascript arrays

使用底层ArrayBuffers创建3D数组(例如myArray [x] [y] [z])的最佳方法(如果可能?)是什么?该数组应包含Uint32Arrays。

在我的情况下,它是一个相当大的阵列(大约200x200x200)。如果我使用类型化的数组,例如uint32,那么迭代它会快得多,因此我想使用ArrayBuffers。或者我错了吗?

1 个答案:

答案 0 :(得分:1)

您可以编写一个简单的函数,将x / y / z索引转换为function arrayIndex(x, y, z, xSize, ySize) { return z + ySize * (y + x * xSize); } 的相应索引。

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xp:panel id="pnlAll">
        <xp:this.data>
            <xe:objectData saveObject="#{javascript:PCModel.save()}"
                var="PCModel">
                <xe:this.createObject><![CDATA[#{javascript:var pc = new com.scoular.model.PC();
var unid = sessionScope.get("key");
if (unid != null) {
    pc.loadByUnid(unid);
    sessionScope.put("key","");
    viewScope.put("readOnly","Yes");
} else {
    pc.create();
    viewScope.put("readOnly","No");
}
viewScope.status = pc.status;
return pc;}]]></xe:this.createObject>
            </xe:objectData>
        </xp:this.data>
        <xp:inputTextarea id="inputTextarea3" cols="1" rows="10"
            disabled="true" value="#{PCModel.notes}">
        </xp:inputTextarea>
        <xp:br></xp:br>
        <xp:button value="Add Notes" id="button1">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:getComponent("dialogAddNotes").show()}]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
        <xp:br></xp:br>
        <xp:div styleClass="modal fade" id="model1" role="dialog">
            <xe:dialog id="dialogAddNotes" styleClass="modal-dialog"
                title="Add Notes">
                <xp:div style="margin-left:10.0px;margin-right:10.0px">
                    <xp:inputTextarea id="inputTextarea4" value="#{viewScope.addNotes}"
                        cols="1" rows="18">
                    </xp:inputTextarea>
                </xp:div>
                <xp:div styleClass="modal-footer">
                    <xp:button type="button" styleClass="btn btn-primary" id="button17"
                        value="Add Notes">
                        <xp:eventHandler event="onclick" submit="true"
                            refreshMode="partial" refreshId="dialogAddNotes">
                            <xp:this.action><![CDATA[#{javascript:var newLne = "\n";
var oldNte = PCModel.notes;
var usrNme:String = userBean.displayName;
var dte = session.createDateTime(@Now());

var lnkStr:String = "Notes added by " + usrNme + " at " + dte + newLne + newLne + viewScope.addNotes + newLne + newLne + oldNte;

var newNotes:String = lnkStr
PCModel.notes = newNotes;
PCModel.save();}]]></xp:this.action>
                        </xp:eventHandler>
                    </xp:button>
                </xp:div>
            </xe:dialog>
        </xp:div>
    </xp:panel>
</xp:view>

有关将一组索引转换为线性索引的一般算法,请参阅Memory layout of multi-dimensional arrays