arrays

Overwriting the Array constructor does not affect [], right?

I just read this: http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx I was under the impression that overwriting Object or Array only had an effect if you chose to use the constructor functions when creating arrays/objects, but, according to that article, it also has an effect on literal creation ({} and [...

Implementing a generic fixed size array with iterator support [C++]

I need an array where size is known at compile time. I know I can use std::vector or boost::array. But that's doesn't teach me how it works internally. Also I couldn't find how to add items into boost::array other than using the initializer. I have written the following code for a generic array. My intention is to get familiar with itera...

Variable Sized Arrays in C

I guess my question is whether the following is valid C int main(void) { int r = 3; int k[r]; return 0; } If so, would some one care to explain why it does not work in Microsoft's C compiler, but in GCC, and when it was added to the C standard. Thank you ...

Are pointers and arrays any different in C?

I'm writing a small C program to do some number crunching, and it needs to pass around arrays between functions. The functions should accept and return pointers, right? For example, this (I know it may not be the most efficient thing): int* reverse(int* l, int len) { int* reversed = malloc(sizeof(*reversed)*len); int i, j; ...

Easy way to implement dynamic views?

View are useful constructions of Python 3. For those who never noticed (like me): for a dictionary d you can write k = d.keys() and even if you update d the variable k will still be giving you the updated keys. You can write then k1 & k2 and it will always give you d1.keys() & d2.keys() I want to implement this for my personal todo mana...

Get array starting with offset

I am using C#, and it's rather annoying that I can't send an array starting from a certain point like in C++. suppose this code: int[] array = new int[32]; foobar (array + 4); //send array starting from the 4th place. this is a weird syntax for C# because we don't have any usable pointers, but surely there's a way to do it? There's ....

Should we use type cast for the object.toArray()???

String[] a = c.toArray(new String[0]); First: Do I need type cast here? (I think we should write like (String[])c.toArray(); BUT I have seen it as just c.toArray() without using type cast. Is this valid? Second: Also why we write new String[0]? ...

Finding the last index of an array

How do you retrieve the last element of an array in C#? ...

How to create Shared VB Array Initialisors for NerdDinner

Hello, I am trying to work my way through the NerdDinner tutorial - and as an exercise I'm converting it to VB as I go. I'm not very far in and after having gotten past the C# Yield statement I'm stuck on Shared VB Array Initialisors. static IDictionary<string, Regex> countryRegex = new Dictionary<string, Regex>() { { "USA", new Regex(...

Get Next and Previous Elements in JavaScript array...

I have a large array, with non-sequential IDs, that looks something like this: PhotoList[89725] = new Array(); PhotoList[89725]['ImageID'] = '89725'; PhotoList[89725]['ImageSize'] = '123'; PhotoList[89726] = new Array(); PhotoList[89726]['ImageID'] = '89726'; PhotoList[89726]['ImageSize'] = '234'; PhotoList[89727] = new Array(); PhotoLi...

How to detect if a variable is an array

What is the best de-facto standard cross-browser method to determine if a variable in JavaScript is an array or not? Searching the web there are a number of different suggestions, some good and quite a few invalid. For example, the following is a basic approach: function isArray(obj) { return (obj && obj.length); } However, note...

How do I select a random element from an array in Python?

The first examples that I googled didn't work. This should be trivial, right? ...

How to change a 2d array from dynamic to static of a specific size?

I currently have the dynamic array: char *myData[500][10]; //myData is the name of an array of[500][10] pointers to type char. I would like to create a static 2d array, 500 rows X 10 columns, each element storing memory for 40 characters. Would below be the correct way of declaring that? char myData[500][10][40]; ...

Building an array from a MySQL Query

I hope it's the heat, this is the second question today and it's one problem after the other. Relatively simple stuff... I have this query ... while ($resultV = mysql_fetch_assoc($metQueryViews)) { $allViews[] = $resultV; } The date it's getting is:- date Count NULL 6 14-5-2009 12 15-5-2009 21 26-6-2009 18 29-6-...

Python Memory Model

I have a very large list Suppose I do that (yeah, I know the code is very unpythonic, but for the example's sake..): n = (2**32)**2 for i in xrange(10**7) li[i] = n works fine. however: for i in xrange(10**7) li[i] = i**2 consumes a significantly larger amount of memory. I don't understand why that is - storing the big number t...

How to assign array of pointers to content of static array?

char myData[505][3][50]; //2D array, each 50 chars long char **tableData[505] = {NULL}; const char* text; text = sqlite3_column_text(stmt, col_index); strcpy(myData[row_index][c_index],text); tableData[row_index] = myData[row_index][c_index]; <--? I would like to assign the pointer to pointer array tableData to the content o...

Best way to remove repeats in a collection in Java?

Hey all, This is a two-part question: First, I am interested to know what the best way to remove repeating elements from a collection is. The way I have been doing it up until now is to simply convert the collection into a set. I know sets cannot have repeating elements so it just handles it for me. Is this an efficient solution? Wou...

Refrencing sprites from an array cocos2d

Normally when adding sprites to a layer in cocos2d I'd just add a pointer to the layer's interface for each sprite to allow it to be referenced in that layer. However, I'm now using for loops to create an array of sprites: -(void) make5Gobs { Sprite *gobs[5]; for(int i = 0; i < 3; i++) { gobs[i] = [Sprite spriteWithFil...

Representing call center customer question logic

I need to solve a problem within job booking software and am hoping to find a good way of doing that. The current system uses a set of check boxes to represent the problem description when a customer rings up. These check boxes are useful to admin, but not really from a customer perspective. My thoughts were to have 1 or more english r...

sort not working with integers?

Trying to get the highest and lowest value from a array that I know will contain only integers seems to be harder than I thought? var numArray = [140000, 104, 99]; numArray = numArray.sort(); alert(numArray[0] + ", " + numArray[numArray.length - 1]); I'd expect this to show "99, 140000". Instead it shows "104, 99". So it seems the sor...