arrays

Why is System.arraycopy native in Java?

I was surprised to see in the Java source that System.arraycopy is a native method. Of course the reason is because it's faster. But what native tricks is the code able to employ that make it faster? Why not just loop over the original array and copy each pointer to the new array - surely this isn't that slow and cumbersome? ...

Add a element to a PHP associative array.

1=>america,2=>India,3=>england Above is my associative array. How can I bring 3=>england to front of the array? ...

How to find the size of integer array...

How to find the size of an integer array in C. Any method available without traversing the whole array once, to find out the size of the array.. Thankss.. ...

Why do arrays in .net only implement IEnumerable and not IEnumerable<T>?

I was implementing my own ArrayList class and was left surprised when I realised that public System.Collections.Generic.IEnumerator<T> GetEnumerator() { return _array.GetEnumerator(); } didn't work. What is the reason arrays don't implement IEnumerator in .NET? Is there any work-around? Thanks ...

C# Object Array CopyTo links both arrays' values?

Okay, I have what I think is a simple question.. or just a case of me being a C# beginner. I have an array of custom objects (clsScriptItem) that I am populating from a database. Once the items are loaded, I want to back them up to "backup" array so I can revert the information back after changing the main array. However, when I use Cop...

Efficient bitshifting an array of int?

Hi, To be on the same page, let's assume sizeof(int)=4 and sizeof(long)=8. Given an array of integers, what would be an efficient method to logically bitshift the array to either the left or right? I am contemplating an auxiliary variable such as a long, that will compute the bitshift for the first pair of elements (index 0 and 1) and...

display an array in html table

I have this array: Array ( [page] => Array ( [0] => add [1] => edit [2] => delete [3] => search ) [category] => Array ( [0] => add [1] => edit [2] => export ) ) And I want it to be displayed as a html table l...

merging indexed array in Python

Suppose that I have two numpy arrays of the form x = [[1,2] [2,4] [3,6] [4,NaN] [5,10]] y = [[0,-5] [1,0] [2,5] [5,20] [6,25]] is there an efficient way to merge them such that I have xmy = [[0, NaN, -5 ] [1, 2, 0 ] [2, 4, 5 ] [3, 6, NaN] [4, NaN, NaN] ...

Javascript array of hrefs

Hi, I am trying to create an array with different hrefs to then attach to 5 separate elements. This is my code: var link = new Array('link1', 'link2', 'link3', 'link4', 'link5'); $(document.createElement("li")) .attr('class',options.numericId + (i+1)) .html('<a rel='+ i +' h...

How to demonstrate memory error using arrays in C++

I'm trying to think of a method demonstrating a kind of memory error using Arrays and C++, that is hard to detect. The purpose is to motivate the usage of STL vector<> in combination with iterators. Edit: The accepted answer is the answer i used to explain the advantages / disadvantages. I also used: this ...

Passing array values in an HTTP request in .NET

What's the standard way of passing and processing an array in an HTTP request in .NET? I have a solution, but I don't know if it's the best approach. Here's my solution: <form action="myhandler.ashx" method="post"> <input type="checkbox" name="user" value="Aaron" /> <input type="checkbox" name="user" value="Bobby" /> <input...

Display data FROM Sheet1 on Sheet2 based on conditional value

Imagine a worksheet with 30 pieces of information, such as: A1= Start Date A2 = End Date A3 = Resource Name A4 = Cost .... A30 = Whatever B1 = 1/1/2010 B2 = 2/15/2010 B3 = Joe Smith B4 = $10,000.00 ... B30 = Blah Blah Now imagine a third column, C. The purpose of the third column is to determine WHICH report that row of data needs to ...

Does fast enumeration in Objective-C guarantee the order of iteration?

Can I expect it to go from the start of an array to the end in order? Can't find anything in the docs about this. i.e. is for (id val in array) { NSLog(@"%@", val); } always going to print out the same as for (int i = 0; i < [array count]; ++i) { NSLog(@"%@", [array objectAtIndex:i]); } ...

How do I know an array of structures was allocated in the Large Object Heap (LOH) in .NET?

After some experimenation using CLR Profiler, I found that: Node[,] n = new Node[100,23]; //'84,028 bytes, is not placed in LOH Node[,] n = new Node[100,24]; //'86,428 bytes, is public struct Node { public int Value; public Point Point; public Color Color; public bool Handled; public Object ...

Shorten array length once element is remove in Java.

Note: Following is my homework/assignment, feel free not to answer if you will. I want to delete/remove an element from an String array(Set) basic, I'm not allowed to use Collections..etc. Now I have this: void remove(String newValue) { for ( int i = 0; i < setElements.length; i++) { if ( setElements[i] =...

C++ multidimensional dynamic array

Let's say I have this to create a multidimensional array dynamically: int* *grid = new int*[gridSizeX]; for (int i=0; i<gridSizeX; i++) { grid[i] = new int[gridSizeY]; } Shouldn't be possible now to access elements like grid[x][y] = 20? ...

Declaring more than one SPIM array causes a syntax error

Below is the beginning of a chunk of SPIM code: .data a: .space 20 b: .space 20 .text set_all: sw $ra,0($sp) li $t0,0 li $t1,10 ............ Unfortunately, the second array I declare ('b') causes the SPIM interpreter to spit out: spim: (parser) syntax error on line 3 of file spim.out b: .space 20 ...

Is there a Pattern in Scala that add a method to an Array object?

Is there a Pattern in Scala that can add a method to an Array object? I am thinking of the implicit conversion of Int to RichInt. But that can't be done as Array is a final class. ...

Javascript - cannot make static reference to non-static function ....

I am making a reference to the Javascript function splice() on an array and I get the error: "Cannot make a static reference to the non-static function splice()" What's going on - how is this a static reference, aren't I referencing an instance of an Array class and its method - how is that static? $(document).ready( function() { v...

JavaScript two-dimensional Array to PHP

Hi I have to send a two-dimensional JavaScript Array to a PHP page. Indeed, I'm working on a form-builder, in which the user can add or remove fields. These fields are added (or removed) using JavaScript (jQuery). When the user is done and hit a 'publish' button, I have to get all the fields concerned and send them to a PHP page which w...