用于线程管理的矢量数据类型 [英] Vector data type for thread management

查看:61
本文介绍了用于线程管理的矢量数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理JSONet项目时

< http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/f083e3925a345f31/bc987f7013afde92>


我得出结论(可能是错误的),Vector数据类型比Array或Hashtable更方便,以保持线程数。

主要好处:i)真实的任何给定时间的长度,ii)auto

在添加/删除新项目时收缩/扩展。总的来说,似乎给出了很多东西你需要通过多次传递来模仿

数组/哈希表元素。


下面的代码是我想要的快速''n'durty版本

工具。这是完全的bs.s.? (想法,而不是代码)。


另请注意,在这段代码中我使用了我的PGO(相当好的

Objecting)编码风格OOP风格和命名空间

安全性,同时让你放松臭名昭着的这个问题。

< html>

< head>

< title> Vector< / title>

< meta http-equiv =" Content-Type"

content =" text / html; charset = iso-8859-1">

< script type =" text / javascript">

function VK_VectorAdd(v){

var i = document.createElement(''OPTION'');

if(typeof v ==''object''){

i.value = v.id || v.toString();

}

else {

i.value = v;

}

this。$ _ vector.appendChild(i);

}

函数VK_VectorItem(i){

返回此。 $ _vector.options [i] .value;

}

函数VK_VectorRemove(i){

this。$ _ vector.options [i] = null;

}

函数VK_VectorClear(){

this。$ _ vector.options.length = 0;

}

函数VK_VectorSize(){

返回此。$ _ vector.options.length;

}

函数Vector(){

if(!(document.createElement)){return null;}

this。$ _ vector = document.createElement(''SELECT'' );

this.add = VK_VectorAdd;

this.item = VK_VectorItem;

this.remove = VK_VectorRemove;

this.clear = VK_VectorClear;

this.size = VK_VectorSize;

}

函数demo(){

var v = new Vector();

v.add(1);

v.add( 'foo'');

alert(v.size());

v.remove(0);

alert(v。 size());

alert(v.item(0));

}

window.onload = demo;

< / script>

< / head>


< body>


< / body>

< / html>

While working on JSONet project
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/f083e3925a345f31/bc987f7013afde92>

I came to the conclusion (possibly wrongly) that Vector data type is
much more convenient than Array or Hashtable to keep threads count.
Major benefits: i) "real" length at any given time, ii) auto
shrink/expand on adding/removing new items. Overall it seems to give as
given a lot of things you have to emulate by multiple pass over
Array/Hashtable elements.

The code below is quick''n''durty version of what I''m thinking to
implement. Is it total b.s.? (the idea, not the code).

Also please note that in this code I used my PGO (Pretty Good
Objecting) coding style which wollows the OOP style and namespace
security while let you relax about the infamous "this" issue.
<html>
<head>
<title>Vector</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function VK_VectorAdd(v) {
var i = document.createElement(''OPTION'');
if (typeof v == ''object'') {
i.value = v.id || v.toString();
}
else {
i.value = v;
}
this.$_vector.appendChild(i);
}
function VK_VectorItem(i) {
return this.$_vector.options[i].value;
}
function VK_VectorRemove(i) {
this.$_vector.options[i] = null;
}
function VK_VectorClear() {
this.$_vector.options.length = 0;
}
function VK_VectorSize() {
return this.$_vector.options.length;
}
function Vector() {
if (!(document.createElement)) {return null;}
this.$_vector = document.createElement(''SELECT'');
this.add = VK_VectorAdd;
this.item = VK_VectorItem;
this.remove = VK_VectorRemove;
this.clear = VK_VectorClear;
this.size = VK_VectorSize;
}
function demo() {
var v = new Vector();
v.add(1);
v.add(''foo'');
alert(v.size());
v.remove(0);
alert(v.size());
alert(v.item(0));
}
window.onload = demo;
</script>
</head>

<body>

</body>
</html>

推荐答案

_vector.appendChild(i);

}

函数VK_VectorItem(i){

返回此。
_vector.appendChild(i);
}
function VK_VectorItem(i) {
return this.


_vector.options [i ] .value;

}

函数VK_VectorRemove(i){

this。
_vector.options[i].value;
}
function VK_VectorRemove(i) {
this.


_vector。 options [i] = null;

}

函数VK_VectorClear(){

this。
_vector.options[i] = null;
}
function VK_VectorClear() {
this.


这篇关于用于线程管理的矢量数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆