473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Vector data type for thread management

VK
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>

Jan 14 '06 #1
14 1335
VK wrote:
<snip>
Also please note that in this code I used my PGO (Pretty
Good Objecting) coding style which wollows the OOP style
LOL
and namespace security while let you relax about the
infamous "this" issue.
You keep banging on about this 'infamous "this" issue' that you
perceive. If you would explain what it is you are talking about someone
may be able to correct whichever of your many misconceptions about
javascript is resulting in you perceiving an issue where there really
isn't one. (Though your tendency to disregard previously given
corrections to some of your legion of misconceptions may put people off
making what may be a pointless effort).
<html>


<snip - The worst example of a Vector-like storage object posted to this
group in the last 3 years. More a demonstration of how not to write
javascript than anything else, but not surprisingly so as VK wrote it.>

</html>

Posting examples that are significantly inferior to previous examples
does not represent a contribution to the group, no matter how much the
effort it takes you to create such pedestrian code leaves you with a
personal sense of achievement and pride.

Richard.
Jan 15 '06 #2
VK

Richard Cornford wrote:
LOL
Well, at least I cheared up someone, so the post already was not
completely useless ;-)
You keep banging on about this 'infamous "this" issue' that you
perceive. If you would explain what it is you are talking about someone
may be able to correct whichever of your many misconceptions about
javascript is resulting in you perceiving an issue where there really
isn't one.
That means that "this" doesn't point on what you would expect. That is
a really strange question from someone who's own code samples are full
of:
....
var self = this;
....

Again I would like to stress out that I'm *not* denying at all the
(anonymous){curling} as a way to program in JavaScript. But I'm
questionning if it as the only one acceptable way.
The worst example of a Vector-like storage object posted to this
group in the last 3 years.


Could you collaborate on it? This does what expected with the minimum
coding. A "bad" would be: i) non cross-browser or ii) runtime
instability or iii) productivity impact.
The first was already checked before posting, but ii) and iii) are
still under test.

Jan 15 '06 #3
In article <11*********************@o13g2000cwo.googlegroups. com>, VK
<sc**********@yahoo.com> writes
While working on JSONet project
<http://groups.google.com/group/comp....se_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.

<snip>

Why do you call it a vector when it isn't a vector ?

John
--
John Harris
Jan 15 '06 #4
VK

John G Harris wrote:
In article <11*********************@o13g2000cwo.googlegroups. com>, VK
<sc**********@yahoo.com> writes
While working on JSONet project
<http://groups.google.com/group/comp....se_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.

<snip>

Why do you call it a vector when it isn't a vector ?


Because it implements the same "ribbon band" functionality I'm looking
for.
Actually why it's not a vector? Going by Java it's a perfect vector
(lesser of course current features set and usual JavaScript memory
management free benefits/drawbacks). Otherwise it is the same perfect
Vector as say Java's ArrayList.

Jan 15 '06 #5
On 15/01/2006 16:32, VK wrote:
Richard Cornford wrote:
[snip]
You keep banging on about this 'infamous "this" issue' that you
perceive.
Well, there is one issue with the this operator, though it isn't the one
VK is referring to: IE and attachEvent. That's a rather annoying
problem, but manageable. :-)

[snip]
That means that "this" doesn't point on what you would expect.
I would be quite amazed if you don't understand how the this operator
value changes predictably. Looking briefly at the archives, I alone have
explained it on at least three separate occasions within the last twelve
months, the most recent of which was thirteen days ago. I'm sure others
have described it during that time, too.

[snip]
The worst example of a Vector-like storage object posted to this
group in the last 3 years.


Could you collaborate on it?


Collaborate, or elaborate? I assume you mean for Richard to elaborate on
the reasons for his negative opinion.

It uses the most bizarre and obtuse storage method I've ever witnessed,
and it uses it inconsistently and without any obvious benefits. You
choose not to use the prototype object - polluting the global object in
the process - despite that being the most obvious choice if your data is
going to be referenced through a public property (and that, in itself,
is an odd decision). Finally, for now, your 'Vector' destroys data
types, with a rather useless approach to dealing with objects.
This does what expected with the minimum coding.
I should think that wrapping an Array object would require the least
effort, or just /using/ an Array object for that matter. Vectors are,
after all, just growable array-like lists (which is what ECMAScript
already provides).
A "bad" would be: i) non cross-browser [...]
So it /is/ bad then. Since when was the document.createElement method
universally implemented?
The first was already checked before posting [...]


Quite a shoddy job you did, then.

Now, what exactly has this got to do with thread management and,
assuming you're referring to the multitasking kind, why is it even
relevant to Javascript (which exposes no threading mechanisms)?

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 15 '06 #6
In article <11**********************@g43g2000cwa.googlegroups .com>, VK
<sc**********@yahoo.com> writes

<snip>
Actually why it's not a vector?

<snip>

A higher Level of Understanding is needed to know that.

John
--
John Harris
Jan 16 '06 #7
VK

John G Harris wrote:
<snip>
Actually why it's not a vector?

<snip>

A higher Level of Understanding is needed to know that.


I am terribly sorry but I'm not currently ready to open another class.
My previous student was really hard (though interesting and promising)
case. I promise to keep you in the hold list. For the time being you
can warm up with the self education. Some interesting startup reading
can be found at:
<http://java.sun.com/j2se/1.3/docs/api/java/util/Vector.html>
and
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html>

:-)

Jan 16 '06 #8
VK wrote:
John G Harris wrote:
<snip>
>Actually why it's not a vector?

<snip>

A higher Level of Understanding is needed to know that.


I am terribly sorry but I'm not currently ready to open
another class. My previous student was really hard ...

<snip>

Are your tying to be patronising? There is little point as it is
ineffective to patronise people once they already regard you with
contempt. You will just look like an arrogant fool instead of just a
fool.

Richard.
Jan 16 '06 #9
VK wrote:
Richard Cornford wrote: <snip>
You keep banging on about this 'infamous "this" issue'
that you perceive. If you would explain what it is you
are talking about someone may be able to correct
whichever of your many misconceptions about javascript
is resulting in you perceiving an issue where there
really isn't one.


That means that "this" doesn't point on what you would
expect.


So your issue is that regardless of the fact that it has been explained
to you in considerable details on numerous occasions you still don't
understand that the value of the - this - keyword is determined always,
and only, by the way in which a function is called, following well
defined rules.

There is no 'infamous "this" issue' outside of the limitations of your
own perception.
That is a really strange question from someone who's own
code samples are full of:
...
var self = this;
...
Using the above expression does not indicate that there is any "issue".
If it was not possible to precisely determine what value - this - has
then it would also not be possible to determine what value - self - has.
Again I would like to stress out that I'm *not* denying at
all the (anonymous){curling} as a way to program in JavaScript.
But I'm questionning if it as the only one acceptable way.
Gibberish!
The worst example of a Vector-like storage object posted to
this group in the last 3 years.


Could you collaborate on it?


Halfwit.
This does what expected with the minimum coding.
"Does what expected"? What exactly did you expect the - return null; -
statement in your constructor to do? The fact that it is there at all
suggests that whatever it is you are expecting differs considerably from
what it will actually do.
A "bad" would be: i) non cross-browser
It certainly isn't cross-browser, it is barely 'both browsers', and
where it fails it will fail in a wide spectrum of different ways.
or ii) runtime instability
How would you define "runtime instability"? Code that has such a wide
range of uncertain outcomes depending on the environment sounds pretty
unstable to me.
or iii) productivity impact.
Code maintenance has a significant impact upon overall productivity. And
code this bad is going to bring considerable maintenance issues. That
may not change your situation but it would be significant in any
collaborative endeavour, but you would be an absolute liability in any
collaborative endeavour.
The first was already checked before posting,
In how many browsers? Two, three? As previous examples have
demonstrated, implementing this type of object can easily be done with
pure language constructs and so work in any javascript environment,
including non-web browsers.
but ii) and iii) are
still under test.


You have demonstrated negligible skill in testing and analyses so I am
sure your results will act to re-enforce you misplaced confidence.

Richard.
Jan 17 '06 #10
VK

Richard Cornford wrote:
Are your tying to be patronising?


In the relevant Message-ID:
<11*********************@f14g2000cwb.googlegroups. com> there was a
*smily* at the bottom which one still may observe. It renders the
response into a humouristic (I still hope) way to say "I believe I
understand what Vector is. Do you? How about reading Java Sun docs?"

Jan 17 '06 #11
In article <11*********************@f14g2000cwb.googlegroups. com>, VK
<sc**********@yahoo.com> writes

John G Harris wrote:
<snip>
>Actually why it's not a vector?

<snip>

A higher Level of Understanding is needed to know that.


I am terribly sorry but I'm not currently ready to open another class.
My previous student was really hard (though interesting and promising)
case. I promise to keep you in the hold list. For the time being you
can warm up with the self education. Some interesting startup reading
can be found at:
<http://java.sun.com/j2se/1.3/docs/api/java/util/Vector.html>
and
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html>

:-)


A better reference is
<URL:http://en.wikipedia.org/wiki/Vector>
and in particular
<URL:http://en.wikipedia.org/wiki/Vector_space>

John
--
John Harris
Jan 17 '06 #12
VK

John G Harris wrote:
A better reference is
<URL:http://en.wikipedia.org/wiki/Vector>
and in particular
<URL:http://en.wikipedia.org/wiki/Vector_space>


It's the geometry meaning of this term, and obviously me and Sun
Microsystems are talking about the programming meaning so what's the
point? :-0

If one says "scope visibility" in this group do you think first about
the microscope resolution?

Jan 17 '06 #13
In article <11**********************@g47g2000cwa.googlegroups .com>, VK
<sc**********@yahoo.com> writes

John G Harris wrote:
A better reference is
<URL:http://en.wikipedia.org/wiki/Vector>
and in particular
<URL:http://en.wikipedia.org/wiki/Vector_space>
It's the geometry meaning of this term, and obviously me and Sun
Microsystems are talking about the programming meaning so what's the
point? :-0


Where on earth do you think programmers got the word vector from ?

Why are you quoting Sun? What have Java's class names got to do with
javascript?

If one says "scope visibility" in this group do you think first about
the microscope resolution?


No, because scope would be written 'scope if it was to do with
microscopes.

John
--
John Harris
Jan 18 '06 #14
JRS: In article <fP**************@jgharris.demon.co.uk>, dated Wed, 18
Jan 2006 20:49:28 remote, seen in news:comp.lang.javascript, John G
Harris <jo**@nospam.demon.co.uk> posted :

No, because scope would be written 'scope if it was to do with
microscopes.


Never presume literacy, Dutch and Danes excepted.

--
© John Stockton, Surrey, UK. *@merlyn.demon.co.uk / ??*********@physics.org ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Correct <= 4-line sig. separator as above, a line precisely "-- " (SoRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)
Jan 19 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
21
by: Peter Olcott | last post by:
I got the previous alias to std::vector working, and found that it takes up the space of a pointer. I want to find a way to do an alias to a std::vector that does not take up any space. Is there...
2
by: ernesto | last post by:
Hi: I want to create my own vector class; I want to provide methods like: class Vector { public: void add(const Object* aVal); void remove(const Object* aVal); };
1
by: themadme | last post by:
im running code thats using threads, everytime i get this debug assertion failed box poping up. It involves with my stl vector. its saying that vector iterators incompatible. the vector...
4
by: Tony | last post by:
Hello, For my application, I have a vector containing data that I need, vector<NODEnode_data; and I have a pointer of vectors which are sorted by some criterion as vector<NODE*np. I have planned...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
5
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.