Jump to content

Magic in arrays


L8V2L

Recommended Posts

var arr = new Array(100);arr[arr.length] = "elem";arr[101]; //elem
FYI, arr[101] is undefined, arr[100] is "elem". On the second line, arr.length is 100, not 101.

Array can have name properties too, and still have their constructor pointing to array.

That's because, like everything else in Javascript, an array is an object. Javascript has no native array data type in the sense that a language like C does, it has array objects. Each array is an instance of an array object. Many Javascript engines contain optimizations to treat arrays like C-style arrays as long as all of the keys are numeric, but once you add string keys then it switches to treating it like any other object and you lose some of the internal speed optimizations. If you disagree that an array is an object, then explain why an array has a constructor. Even in C arrays are random access, it can determine the specific memory address of any item in the array by knowing the starting address of the data (the address of the array itself), the data type of each element (the size in memory per element), and the offset. That's also the reason why array indexes today are 0-based.

I ask what is the mechanism behind retrieving arrays elements via there keys? Does it iterate, or is it magic

Neither, it is direct random access. It does not iterate through the entire array to get a certain element, it accesses the element directly. I believe that in some browsers arrays and objects are implemented like a hash table, like davej mentioned.

Where going to go with it's just magic.

When you start thinking that what computers do is somehow magic or supernatural, then you're completely lost. Computers are the most deterministic things on the planet. Computers have less randomness than a crystal forming. A computer can't even generate a truly random number.
Link to comment
Share on other sites

 

var arr = new Array(100);arr[arr.length] = "elem";arr[101]; //elem
FYI, arr[101] is undefined, arr[100] is "elem". On the second line, arr.length is 100, not 101.
Yes you're right:
Array(100);
explicit the length, not the number of index.

That's because, like everything else in Javascript, an array is an object. Javascript has no native array data type in the sense that a language like C does, it has array objects. Each array is an instance of an array object. Many Javascript engines contain optimizations to treat arrays like C-style arrays as long as all of the keys are numeric, but once you add string keys then it switches to treating it like any other object and you lose some of the internal speed optimizations. If you disagree that an array is an object, then explain why an array has a constructor. Even in C arrays are random access, it can determine the specific memory address of any item in the array by knowing the starting address of the data (the address of the array itself), the data type of each element (the size in memory per element), and the offset. That's also the reason why array indexes today are 0-based.

I never said arrays wasn't object.... For now own we call
{0:0,1:1,2:2}
associate array, or key/value pairs. I was refering to this as comparison.

Neither, it is direct random access. It does not iterate through the entire array to get a certain element, it accesses the element directly. I believe that in some browsers arrays and objects are implemented like a hash table, like davej mentioned.

Yes, I read the hash table link Ingolme post me... But don't really understand it... If I had to give a visual representation, I'll say it is like a map that give the location of the value... Like an associate array, or an index array.

When you start thinking that what computers do is somehow magic or supernatural, then you're completely lost. Computers are the most deterministic things on the planet. Computers have less randomness than a crystal forming. A computer can't even generate a truly random number.

No I don't. I just wasn't giving an answer, or no one truly understood what I was asking. And your right, computer are the less randomless things--not including bugs. But even with bugs, there is logic behind it--on this earth. Everything is program to predictable action. Edited by L8V2L
Link to comment
Share on other sites

Data structures: linked listcircular bufferB-treestackhash table

... Hey davej... Do you mind explaining each one in your own words.... Just asking.
Link to comment
Share on other sites

var arr = new Array(100);arr[arr.length] = "elem";arr[101]; //elem
FYI, arr[101] is undefined, arr[100] is "elem". On the second line, arr.length is 100, not 101.

 

In the instance when using arr.length between the square brackets like on the second line, does JS interpret arr.length as 100 there instead of 101 in that instance? (I see that it does but was wondering why in that instance. Thanks.)

Link to comment
Share on other sites

... Hey davej... Do you mind explaining each one in your own words.... Just asking.

or look them up? We've already gone over this. If you don't understand something and need clarification on specific concepts, please go ahead. Otherwise, you're just asking everyone to do the job that you could just be doing yourself with Google.

Link to comment
Share on other sites

or look them up? We've already gone over this. If you don't understand something and need clarification on specific concepts, please go ahead. Otherwise, you're just asking everyone to do the job that you could just be doing yourself with Google.

:,1( why must he be so.... Or with wiki.
Link to comment
Share on other sites

In the instance when using arr.length between the square brackets like on the second line, does JS interpret arr.length as 100 there instead of 101 in that instance?

The length is 100 at that point, since it was defined with 100 elements. The indexes are 0-99. Setting element 100 causes there to be one more element after that, and the length is 101. In practice, you wouldn't use that syntax to add new elements, you would use Array.push instead.
  • Like 1
Link to comment
Share on other sites

Data structures: linked listcircular bufferB-treestackhash table

Along with these too:This is a list of data structures. For a wider list of terms, see list of terms relating to algorithms and data structures. For a comparison of running time of subset of this list see comparison of data structures.Data typesEditPrimitive typesBoolean, true or falseCharacterFloating-point, single-precision real number valuesDouble, a wider floating-point sizeInteger, integral or fixed-precision valuesEnumerated type, a small set of uniquely named valuesComposite types(Sometimes also referred to as Plain old data structures.)ArrayRecord (also called tuple or struct)UnionTagged union (also called a variant, variant record, discriminated union, or disjoint union)Abstract data typesArrayContainerMap/Associative array/DictionaryMultimapListSetMultisetPriority queueQueueDequeStackStringTreeGraphSome properties of abstract data types:Structure Stable Unique Cells per NodeBag (multiset) no no 1Set no yes 1List yes no 1Map no yes 2"Stable" means that input order is retained.Other structures such as "linked list" and "stack" cannot easily be defined this way because there are specific operations associated with them.Linear data structuresArraysArrayBidirectional mapBit arrayBit fieldBitboardBitmapCircular bufferControl tableImageDynamic arrayGap bufferHashed array treeHeightmapLookup tableMatrixParallel arraySorted arraySparse arraySparse matrixIliffe vectorVariable-length arrayListsDoubly linked listArray listLinked listSelf-organizing listSkip listUnrolled linked listVListXor linked listZipperDoubly connected edge listDifference listTreesEditTree (data structure)Binary treesAA treeAVL treeBinary search treeBinary treeCartesian treeOrder statistic treePagodaRandomized binary search treeRed-black treeRopeScapegoat treeSelf-balancing binary search treeSplay treeT-treeTango treeThreaded binary treeTop treeTreapWeight-balanced treeBinary data structureB-treesB-treeB+ treeB*-treeB sharp treeDancing tree2-3 tree2-3-4 treeQueapFusion treeBx-treeAListHeapsHeapBinary heapWeak heapBinomial heapFibonacci heapAF-heap2-3 heapSoft heapPairing heapLeftist heapTreapBeapSkew heapTernary heapD-ary heapBrodal queueTriesIn these data structures each tree node compares a bit slice of key values.TrieRadix treeSuffix treeSuffix arrayCompressed suffix arrayFM-indexGeneralised suffix treeB-trieJudy arrayX-fast trieY-fast trieCtrieMultiway treesTernary treeK-ary treeAndor tree(a,B)-treeLink/cut treeSPQR-treeSpaghetti stackDisjoint-set data structureFusion treeEnfiladeExponential treeFenwick treeVan Emde Boas treeRose treeSpace-partitioning treesThese are data structures used for space partitioning or binary space partitioning.Segment treeInterval treeRange treeBinKd-treeImplicit kd-treeMin/max kd-treeAdaptive k-d treeQuadtreeOctreeLinear octreeZ-orderUB-treeR-treeR+ treeR* treeHilbert R-treeX-treeMetric treeCover treeM-treeVP-treeBK-treeBounding interval hierarchyBSP treeRapidly exploring random treeApplication-specific treesAbstract syntax treeParse treeDecision treeAlternating decision treeMinimax treeExpectiminimax treeFinger treeExpression treeHashesEditBloom filterCount-Min sketchDistributed hash tableDouble HashingDynamic perfect hash tableHash array mapped trieHash listHash tableHash treeHash trieKoordePrefix hash treeRolling hashMinHashQuotient filterCtrieGraphsEditGraphAdjacency listAdjacency matrixGraph-structured stackScene graphBinary decision diagramZero-suppressed decision diagramAnd-inverter graphDirected graphDirected acyclic graphPropositional directed acyclic graphMultigraphHypergraphOtherEditLightmapWinged edgeDoubly connected edge listQuad-edgeRouting tableSymbol tableExternal linksEditConclusion:There is many ways to organize data. And I can see XML and JSON in... I would say all of them--concept wise--, in tree structure to csv. Edited by L8V2L
Link to comment
Share on other sites

Thanks for the link. From what I have read, it sound a lot like xml, and json.

 

No, it's nothing like XML and JSON.

 

XML and JSON are not data structures they're formats for representing data in a string.

XML is a text representation of the DOM. The DOM of an XML document is a type of tree.

JSON is a text representation of a javascript object. The data structure is part of Javascript, JSON is just one way to show the structure of that object.

 

If you truly want to know programming then you have to learn data structures among other things. Forget XML and JSON, go back to the basics. You clearly do not understand enough.

 

Don't ask me to give you explanations for every little thing, either read a book or go take a programming course and have a tutor. You're not paying me so I don't need to go out of my way to break things down for you. You have to learn things in order because lots of things require prior knowledge to be understood. You can't truly understand XML if you don't know what a tree is.

Link to comment
Share on other sites

I'm so bias against java... I think it cause of the relationship with JavaScript that i don't like the language.... It seem dirty. But C and C++ seem very clean--even know I haven't study either one of them to be saying that. Basex is built with java... Which I hate... Exist is built with c/c++ which I love but compare the features and abilities with basex and you'll see basex win.

Link to comment
Share on other sites

How are you having opinions on things you know nothing about?

 

Java has no relationship with Javascript.

What do you mean when you say C and C++ are "clean"?

Can you list the actual features BaseX has that makes it better than Exist?

Link to comment
Share on other sites

How are you having opinions on things you know nothing about?Java has no relationship with Javascript.What do you mean when you say C and C++ are "clean"?Can you list the actual features BaseX has that makes it better than Exist?

I'm speaking on the whole ordeal with java and JavaScript.C/C++ give off a blue clean color. Java give off an red orangey color.My favorite color are blue and purple. Language featuresName License Native Language XQuery 3.0 XQuery Update XQuery Full Text EXPath Extensions EXQuery Extensions XSLT 2.0BaseX BSD License Java Yes Yes Yes Yes Yes YeseXist LGPL License Java Partial Proprietary[11] Proprietary Yes Yes YesMarkLogic Server Commercial C++ Partial Proprietary Proprietary No No YesSedna Apache License C++ No Yes Yes No No NoSupported APIsName XQJ XML:DB RESTful RESTXQ WebDAVBaseX Yes Yes Yes Yes YeseXist Yes Yes Yes Yes YesMarkLogic Server Yes No Yes Yes YesSedna Yes Yes No No No
Link to comment
Share on other sites

C/C++ give off a blue clean color. Java give off an red orangey color.

 

My favorite color are blue and purple.

:facepalm:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...