在阅读有关如何使用bitmasks存储布尔值后,我有点困惑.我想有一组布尔值,然后为每个值组合生成一个唯一的整数.以下是目前的系统:
var a = 1 << 1
var b = 1 << 2
var c = 1 << 3
var d = 1 << 4
var uniqueint1 = getInt(true, false, false)
var uniqueint2 = getInt(true, true, false)
var uniqueint3 = getInt(true, true, true)
// ...
function getInt(x, y, z) {
var value = a
if (x) value = value | b
if (y) value = value | c
if (z) value = value | d
return value
}
Run Code Online (Sandbox Code Playgroud)
但问题是,我不确定我是否应该按照以下方式处理"不"的情况:
function …
Run Code Online (Sandbox Code Playgroud) 给定这样的结构:
var node = { children: [] }
Run Code Online (Sandbox Code Playgroud)
也就是说:
children
财产。parent
财产。nextSibling
财产。如何使用自上而下的方法构建一个带有所有叶节点路径的平面数组列表:
所以这是一个示例数据:
var node = {
item: 1,
children: [
{
item: 2,
children: [
{
item: 3,
children: [
{
item: 4,
children: []
},
{
item: 5,
children: []
},
{
item: 6,
children: [
{
item: 7,
children: []
},
{
item: 8,
children: []
},
{
item: 9,
children: []
}
]
} …
Run Code Online (Sandbox Code Playgroud) 在典型的内存布局中,有 4 项:
我是内存布局的新手,所以我想知道 v8(它是一个 JIT 编译器并动态生成代码)是否将此代码存储在内存的“代码”段中,或者只是将它与其他所有内容一起存储在堆中。我不确定操作系统是否允许您访问代码/文本,因此不确定这是否是一个愚蠢的问题。
想知道是否可以将大型数组传递给WebGL着色器,如下所示:
// array here
uniform vec4[huge] mydynamicarray;
void main() {
// iterate through the array here to perform processing on it,
// then write value to gl_Position
gl_Position = ...;
}
Run Code Online (Sandbox Code Playgroud)
然后将这样填充:
gl.uniform4fv(myarrayloc, myarray)
Run Code Online (Sandbox Code Playgroud)
我已经看到了许多如何传递这样的值的示例,例如:
gl.uniform4fv(offsetLoc, [1, 0, 0, 0])
Run Code Online (Sandbox Code Playgroud)
但是我还没有看到是否可以传递一个很大的,动态大小的数组。
这样做的原因是您可以处理2个数组:
根据我的理解,Haskell中有4种"类型":
data
=
在data
类型之后是什么; 在技术上不是类型,我不认为)type
class
instance
问题是:
data
类型和class
类型类之间的区别是什么.它们看似相似,但显然它们有一些不同的特征.与(3)相同.data
类型和instance
类型类实例之间的区别是什么.我是Haskell的新手.
我见过的关于 ArrayBuffer 的唯一真正的教程来自HTML5Rocks。但我特别想知道如何操作单个字节。例如,Mozilla 的 ArrayBuffers 上的这个卡通显示了一个包裹在 Uint8Array 视图中的 ArrayBuffer 的图像:
它给人的感觉是你可以用 ArrayBuffer 做到这一点:
var x = new ArrayBuffer(10)
x[0] = 1
x[1] = 0
...
x[9] = 1
Run Code Online (Sandbox Code Playgroud)
即手动设置字节。但是我还没有看到任何关于这种功能的文档。相反,您似乎应该使用 TypedArray 组件之一或 DataView:
var x = new ArrayBuffer(100)
var y = new DataView(x)
y.setUint32(0, 1)
console.log(y.getUint32(0)) // 1
console.log(x[0]) // undefined
Run Code Online (Sandbox Code Playgroud)
但是,在使用 DataView 操作 ArrayBuffer 之后,您似乎无法直接访问 ArrayBuffer 上的任何字节。
尝试使用 ArrayBuffer 和 DataView 进行其他操作时,我感到困惑:
var x = new ArrayBuffer(100)
var y = new DataView(x)
y.setUint32(0, 1)
y.setUint32(1, 2) …
Run Code Online (Sandbox Code Playgroud) 说我有串状foo
,bar
,baz
,hello
,world
,等多达256个独特的字符串,所以不是很多.对于所有意图和目的,它可以很容易地是200个字符串或32个字符串.希望该解决方案可以处理任意大小的集合.
所以你取这个字符串并以某种方式将它映射到整数0-255.不做这个:
strings[currentString] = ID++
// strings['foo'] = 0
// strings['bar'] = 1
// strings['baz'] = 2
// ...
Run Code Online (Sandbox Code Playgroud)
这将取决于他们插入的顺序.理想情况下,它们可能是以某种方式从单个字符或字节的散列中唯一生成的,我不确定.但它将是一个没有内存的函数,从一组已知大小中获取任意字符串并将其映射为整数,因此更像:
// strings['foo'] = 6 + 15 + 15 = 36
// strings['bar'] = 2 + 1 + 16 = 19
// ...
Run Code Online (Sandbox Code Playgroud)
虽然这不会因为碰撞而起作用.我不知道如何设计像这样的哈希函数.所以不管怎样,别的东西都可以用来避免碰撞.
function hash(string, size) {
// return unique integer within size
}
hash('foo', 256) // something like 123
hash('bar', 256) // something …
Run Code Online (Sandbox Code Playgroud)如果我进入/usr/local/lib
,我会看到一堆文件夹和.dylib
文件,我很确定是动态链接的库文件。如果我去的话,/usr/local/include
它有一堆.h
文件,每个文件都有未编译的纯C源代码。
如果我在放置.h
文件/usr/local/include/mylib.h
,而在本地放置另一个文件.c
或.h
文件~/Desktop/test/foo.c
,则在其中foo.c
可以包含mylib.h
:
~/Desktop/test/foo.c
#include <mylib.h>
int
main() {
puts("Hello World");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我遵循这个,我会在终端中写这个:
$ clang -Xlinker -v
@(#)PROGRAM:ld PROJECT:ld64-351.8
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
Run Code Online (Sandbox Code Playgroud)
于是/usr/local/lib
就在那里,这是一堆.dylib
文件。我无法修改/usr/lib
。
我的问题是如何使用本地C库(例如) …
javascript ×4
algorithm ×2
arrays ×2
arraybuffer ×1
bitmask ×1
c ×1
clang ×1
colors ×1
combinations ×1
database ×1
function ×1
hash ×1
haskell ×1
jit ×1
linker ×1
macos ×1
memory ×1
nomenclature ×1
string ×1
typed-arrays ×1
types ×1
unicode ×1
v8 ×1
webgl ×1