arrays

Converting hash to string in Ruby.

Let's say we have a hash: flash = {} flash[:error] = "This is an error." flash[:info] = "This is an information." I would like to convert it to a string: "<div class='error'>This is an error.</div><div class='info'>This is an information". in nice one liner ;) I found something like that: flash.to_a.collect{|item| "<div class='#{...

Why aren't Array methods built into an Array instance?

Sorry for what is probably a silly question but it's bugging me... int[] i = {3, 2, 1}; //why Array.Sort(i); //instead of i.Sort(); char c = 'c'; //why char.IsLetter(c); //instead of c.Isletter(); ...

Objective C creating custom arrays

In other languages I could create a class then use this to create an array of objects in that class eg class price which is used in a performance class to define a price[] prices; in objective C i cant get this to work, how do you do it? The price class is an inherit of NSObject, can I use NSMutableArray? ...

I am stuck with php array()?

Does anybody have an idea why following array() is passing into function. I am not able to understand the array() function. I know, if $_POST dont have any value, it will pass array(). but what are the value in array()? SomeFunction($_POST ? $_POST : array()); ...

How do you concatenate Lists in C#?

If I have: List<string> myList1; List<string> myList2; int placeToCheckValues = 0; //Used for breakpoints since the values don't get updated until after the line is executed myList1 = getMeAList(); placeToCheckValues = 0; //Checked myList1 here, it contains 4 strings myList2 = getMeAnotherList(); placeToCheckValues = 0; //Checke...

Finding smallest value in an array most efficiently

There are N values in the array, and one of them is the smallest value. How can I find the smallest value most efficiently? ...

C++ array initialization

Why can’t I initialize a local array with a string ...

Why this code crashes?

For C++ gurus: Can you please elaborate why this code crashes at the places mentioned? I am a bit stumped on this. I guess that it has got something to do with sizeof(int) but I am not so sure. Can anybody explain? class Base { public: virtual void SomeFunction() { printf("test base\n"); } int m_j; }; class Der...

Convert BYTE buffer (0-255) to float buffer (0.0-1.0)

How can I convert a BYTE buffer (from 0 to 255) to a float buffer (from 0.0 to 1.0)? Of course there should be a relation between the two values, eg: 0 in byte buffer will be .0.f in float buffer, 128 in byte buffer will be .5f in float buffer, 255 in byte buffer will be 1.f in float buffer. Actually this is the code that I have: for (...

C++ auto_ptr for arrays

In short, I am wondering if there is an auto_ptr like type for arrays. I know I could roll my own, I'm just making sure that there isn't already something out there. I know about vectors as well. however I don't think I can use them. I am using several of the Windows APIs/SDKs such as the Windows Media SDK, Direct Show API which in or...

Creating a custom array within an array sort function in Javascript.

What would i need to put in the SortIP function to make the custom sort function sort the array by the last digit of the IP number. This doesn't work. function SortIP(a, b) { return a[0][3] - b[0][3]; } LAN = new Array ( ["ADSL Router", [192, 168, 0, 1]], ["Gary's Mac", [192, 168, 0, 15]], ["Network Switch", [192, 168, ...

What is the difference betweeen %INC and @INC?

What is the difference between %INC and @INC in Perl? ...

Is a struct of pointers guaranteed to be represented without padding bits?

I have a linked list, which stores groups of settings for my application: typedef struct settings { struct settings* next; char* name; char* title; char* desc; char* bkfolder; char* srclist; char* arcall; char* incfold; } settings_row; settings_row* first_profile = { 0 }; #define SETTINGS_PER_ROW 7 When I load values ...

Best way to reuse an element from an Array?

I have a Array of Characters objects (extends Sprite). public static var charlist:Array; When a Character die, I set a flag to indicate that. char.die = true; When I spawn a new player, I check against this flag, to reuse the slot. This is where the problem comes. What is the best way to do that? Actually I have this approach: cha...

What is the difference between pointer and array in the following context?

#include <cstring> int main() { char *pName = new char[10]; char dummy[] = "dummy"; strcpy(pName + 0,dummy);//how this is different from -->this works strcpy(pName[0],dummy);//this one...--> error C2664: 'strcpy' : //cannot convert parameter 1 //from 'char' to 'c...

Can a Ruby method yield as an iterator or return an array depending on context?

I have an arbitrary method in Ruby that yields multiple values so it can be handed to a block: def arbitrary yield 1 yield 2 yield 3 yield 4 end arbitrary { |x| puts x } I'd like to modify this method so that, if there is no block, it just returns the values as an array. So this construct would work as well: myarray = arbitr...

How can I remove duplicates in an object array in PHP?

I have an object like this: class FanStruct{ public $date; public $userid; function __construct($date, $id){ $this->date = $date; $this->userid = $id; } } I have maximum of 30 of them in an array, and they are sorted by $userid. What is the best way to go though the array, and remove duplicate objects base...

Compare associative array with standard array values PHP

I have a set of ids and names in an associative array and in my other array I have my list of id's that I want to compare against the first list. I'd like to be able to perform an intersection type search function without losing the names from the associative array. I've though about doing a nested foreach, but it seems like this proce...

Clojure representing byte array

In java i would read the whole file in to byte array and do some processing with it. Now i want to implement the same algorithm in clojure. What i am wondering is can i use a list instead of an array? I know i can create array from clojure but what is the lisp way of handling this? ...

C: create a pointer to two-dimensional array

Hi, i need a ptr to a static 2-dimensional array. How is this done? static uint8_t l_matrix[10][20]; void test(){ uint8_t **matrix_ptr = l_matrix; //wrong idea } i dont get it, but all kinds of errors like: warning: assignment from incompatible pointer type subscripted value is neither array nor pointer error: invalid use of f...