arrays

std::vector is so much slower than plain arrays?

I've always thought it's the general wisdom that std::vector is "implemented as an array," blah blah blah. Today I went down and tested it, seems to be not so: Here's some test results: UseArray completed in 2.619 seconds UseVector completed in 9.284 seconds UseVectorPushBack completed in 14.669 seconds The whole thing completed in 26....

Format PayPal array nicely in PHP

I have an array returning like this from PayPal: Array ( [responseEnvelope.timestamp] => 2010-09-07T23%3A06%3A33.737-07%3A00 [responseEnvelope.ack] => Success [responseEnvelope.correlationId] => b9d9ca4f54f44 [responseEnvelope.build] => 1437064 [estimatedAmountTable.currencyConversionList(0).baseAmount.code] => USD ...

matching sub arrays on array and count them

Hi, i am having an array Array ( [1] => Array ( [0] => 1 [1] => 3 ) [2] => Array ( [0] => 1 [1] => 2 ) [3] => Array ( [0] => 1 [1] => 3 ) ) and i need to find the common subarrays In the above examp...

Remove duplicates from a large integer array using Java

Hello all! Do you know of any time efficient way to remove duplicated values from a very big integer array using Java? The size of the array depends on the logged in user, but will always exceed 1500000 unsorted values with some duplicates. Every integer contains a number between 100000 and 9999999. I tried converting it to a List, but...

How go get everything from between paranthesis in PHP ?

Array( [1] => put returns (between) paragraphs [2] => (for) linebreak (add) 2 spaces at end [3] => indent code by 4 (spaces!) [4] => to make links ) Want to get text inside brackets (for each value): take only first match remove this match from the value write all matches to new array After function arrays should look like: Array(...

Get the middle of an Ix range in O(1) time in Haskell

I was playing around with this code kata in Haskell, and I came across the question in the topic. It's trivial to find the midpoint of an array whose indexes are a single numerical value, but Haskell's array indexes can be any instance of the Ix typeclass, including, for example, the tuple (Int, Word, Card) where card is an instance of ...

How to create an array from this result set (nested categories stored in databased with traversal model)?

Based on this question: http://stackoverflow.com/questions/1310649/getting-a-modified-preorder-tree-traversal-model-nested-set-into-a-ul The logic bellow is used to build an ordened list, but how to do the same with an array? I want to build a nested array. // bootstrap loop $result = ''; $currDepth = -1; // -1 to get the outer <ul...

Array sorting/searching technique in PHP

Hi, In PHP I have an array let say $array = array(2, 1, 8, 3, 6, 0, 10, 10)and I want to get second largest value of that array. Which sorting/searching technique will be best & how could I use it? ...

C# - is string actually an array of chars or does it just have an indexer?

Hi, As the following code is possible in C#, I am intersted whether string is actually an array of chars: string a="TEST"; char C=a[0]; // will be T ...

call by reference with array

What I want to do is something like this: void dosth(bool& a) { a[2] = false; } int main() { bool a[10]; dosth(a); return 0; } I want to call by reference, with an array as argument. How to realize this? Thx ...

how can i get specific value in array

I will explain clearly $array = array("1" => array(0 =>"aa",1 =>"bb", 2 => "cc",3=>"dd"), "2" => array(0 =>"aa1",1 =>"bb1", 2 => "cc1",3=>"dd1")); In this two dimension are $array2[$a][$b]; i know $a value ..$b is unknown if i using $a =1 means i want to filter array(0 =>"aa",1 =>"bb", 2 => "cc",3=>"dd") this arr...

How to add a page inside some levels using Zend_Navigation?

I'm using a XML (click here to see) with Zend_Navigation to render this: which Menu Principal is the first level, then Home and Quem Somos, then the dropdown is the third and last level. I want this last list to be dynamic (querying from the database). I found out that I can use the method addPages($array) in order to dynamically rend...

What's the 'Ruby way' to iterate over an array - from array[n] to array[n - 1]?

Say I have an array of size 5. I want to take an index (from 0-4) as input, and iterate through the array, starting at the supplied index. For example, if the index given was 3, I want to iterate like so: arr[3] arr[4] arr[0] arr[1] arr[2] I can think of plenty of ways to do this - but what's the Ruby way to do it? ...

Getting json response into a javascript array

Hi all, If I have the following function that iterates through a json response object (val2): function test(val2){ jQuery.each(val2.maps, function(j, val3) { maps = new Array({ id: val2.maps[j].id, parent: val2.maps[j].parent, image: val2.maps[j].image, data: val2.maps[j...

Can you pass an array from javascript to asp.net mvc controller action without using a form?

I know that if I have a form with multiple elements with the same name I can use this to bind to an array, but is there any way to pass an array from a javascript function to an ASP.NET MVC controller action without using a form? ...

array as function argument

Hi, consider the following code: #define MAX_COUNT 4 static int foo(int w[MAX_COUNT]) { int *p = w; if (w) { w[0] = 10; w[1] = 20; w[2] = 30; w[3] = 40; } return 0; } is it portable and legal pass NULL to above defined foo() (for example, for a situation when I don't need w[] be altered)? Given that the name...

"Array to Hash" transform in Ruby

Hello. I need to transform ["a", "b", "c", "d"] to {:a => {:b => {:c => "d" }}} ? Any ideas ? Thanks ...

How do you write a method that prints objects in a array in java?

How do you print objects in a array in java? ...

Refactoring array in PHP

I have the next array Array ( [0] => Array ( [id] => 22 [title] => RankTitle ) [1] => Array ( [id] => 32 [title] => RankTitle2 ) ) How can I get the next array in php?: Array ( [22] => RankTitle [32] => RankTitle2 ) ...

2 dimensional array, calculating maximum value

Hey everyone, I'm trying to get the maximum value in a line in an 2d array. For example is this greyscale image. For me it's no problem to calculate the horizontal and vertical maximum grey value. However, I don't have a clue how to calculate an angled line (green line) from this 2d array. Anyone can help me out with this. ...