Search Results

Search found 1898 results on 76 pages for 'structures'.

Page 30/76 | < Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >

  • Need help with java map and javabean

    - by techoverflow
    Hi folks, I have a nested map: Map<Integer, Map<Integer, Double>> areaPrices = new HashMap<Integer, Map<Integer, Double>>(); and this map is populated using the code: while(oResult.next()) { Integer areaCode = new Integer(oResult.getString("AREA_CODE")); Map<Integer, Double> zonePrices = areaPrices.get(areaCode); if(zonePrices==null) { zonePrices = new HashMap<Integer, Double>(); areaPrices.put(areaCode, zonePrices); } Integer zoneCode = new Integer(oResult.getString("ZONE_CODE")); Double value = new Double(oResult.getString("ZONE_VALUE")); zonePrices.put(zoneCode, value); myBean.setZoneValues(areaPrices); } I want to use the value of this Map in another method of the same class. For that I have a bean. How do I populate it on the bean, so that I can get the ZONE_VALUE in this other method In my bean I added one new field as: private Map<Integer, Map<Integer, Double>> zoneValues; with getter and setter as: public Map<Integer, Map<Integer, Double>> getZoneValues() { return zoneValues; } public void setZoneValues(Map<Integer, Map<Integer, Double>> areaPrices) { this.zoneValues = areaPrices; } What I am looking for to do in the other method is something like this: Double value = myBean.get(areaCode).get(zoneCode); How do I make it happen :(

    Read the article

  • how to design a db like Facebook where users can update their status and of the fb page as admin

    - by Harsha M V
    i am designing a database where users can update status messages of theirs and they can create pages groups like facebook fan page and post status like the admin of the page and not as a user. user(id, name..) group(id, name...) group_admin(group_id, user_id) this is my set up. Is this the way to do it. How to post under the group as an admin. will i need to make a check to every user if he is the admin or not ?

    Read the article

  • Segmentation fault in a function to reverse a singly linked list recursivley.

    - by Amanda
    I am implementing a function to recursively reverse a linked-list, but getting seg-fault. typedef struct _node { int data; struct _node *next; } Node, *NodeP; NodeP recursiveReverseList(NodeP first){ if(first == NULL) return NULL; if(first->next == NULL) return first; NodeP rest = recursiveReverseList(first->next); rest->next = first; first->next = NULL; return first; } Can you please help? P.S. The iterative version is working fine though. Its not homework. Just practicing C. Thank you all :)

    Read the article

  • servlet ArrayList and HashMap problem witch result

    - by nonameplum
    Hi, I have that code List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); Map<String, Object> item = new HashMap<String, Object>(); data.clear(); item.clear(); int i = 0; while (i < 5){    item.put("id", i);    i++;    out.println("id: " + item.get("id"));    out.println("--------------------------");    data.add(item); } for(i=0 ; i<5 ; i++){    out.println("print data[" + i + "]" + data.get(i)); } Result of that is: id: 0 -------------------------- id: 1 -------------------------- id: 2 -------------------------- id: 3 -------------------------- id: 4 -------------------------- print data[0]{id=4} print data[1]{id=4} print data[2]{id=4} print data[3]{id=4} print data[4]{id=4} Why only last element is stored?

    Read the article

  • In-memory data structure that supports boolean querying

    - by sanity
    I need to store data in memory where I map one or more key strings to an object, as follows: "green", "blue" -> object1 "red", "yellow" -> object2 I need to be able to efficiently receive a list of objects, where the strings match some boolean criteria, such as: ("red" OR "green") AND NOT "blue" I'm working in Java, so the ideal solution would be an off-the-shelf Java library. I am, however, willing to implement something from scratch if necessary. Anyone have any ideas? I'd rather avoid the overhead of an in-memory database if possible, I'm hoping for something comparable in speed to a HashMap (or at least the same order of magnitude).

    Read the article

  • How can i optimize this python code

    - by RandomVector
    def maxVote(nLabels): count = {} maxList = [] maxCount = 0 for nLabel in nLabels: if nLabel in count: count[nLabel] += 1 else: count[nLabel] = 1 #Check if the count is max if count[nLabel] > maxCount: maxCount = count[nLabel] maxList = [nLabel,] elif count[nLabel]==maxCount: maxList.append(nLabel) return random.choice(maxList) nLabels contains a list of integers. The above function returns the integer with highest frequency, if more than one have same frequency then a randomly selected integer from them is returned. E.g. maxVote([1,3,4,5,5,5,3,12,11]) is 5

    Read the article

  • Java - Count words in two documents

    - by user552961
    Good Morning - it is school assignment, I am not asking for any source code (if you can provide any pesudo code it would be awesome). Here is the problem :( I have to create a term frequency table. It is not pure TF, I just need to count the words and write down. I know basic steps to do it 1 - extract all terms (I can do it with file reader) 2 - remove repeating terms (I can do it with TreeMap) The output of 2nd step would be Niga, ponga, dinga, bitlo, etc. 3 - Now I have to see if there is any word in current file from above terms or not, if yes then I will count. Now this is my problem, I stucked on step 3 :( I have some idea how to count words with TreeMap (treemap.containskey etc.) but it would be global count not local count for each file :( Any pseudo code?

    Read the article

  • How to transfer large file (File size > Heap Size) over the network?

    - by neo
    How to transfer large file (File size Heap/RAM Size) over the network ? Lets say I have file (size 10GB) I want to transfer it machine a (RAM 512mb) to machine b (RAM 512mb). Want achieve this using java code. First, is it possible ? Any recommendation on framework. If possible, can we speed this up using threading ? Important criteria: file's data sequence needs to be maintained during transfer. Any example will be great help.

    Read the article

  • What is the proper design of storing temporary users? [closed]

    - by Mendy
    In SO site both real users and temporary users can add a new questions. I assume each user type has a different table. My question is how can I attach the question to the right user? I assuming the temp users have their own table from the following reasons: Temp users don't have all the data that real users have. like: email, password, and all users details. On the other hand, temp users are a lot more then real users. So it make more sense to have they in their own table.

    Read the article

  • Data structure name: combination array/linked list

    - by me_and
    I have come up with a data structure that combines some of the advantages of linked lists with some of the advantages of fixed-size arrays. It seems very obvious to me, and so I'd expect someone to have thought of it and named it already. Does anyone know what this is called: Take a small fixed-size array. If the number of elements you want to put in your array is greater than the size of the array, add a new array and whatever pointers you like between the old and the new. Thus you have: Static array ————————————————————————— |1|2|3|4|5|6|7|8|9|a|b|c| ————————————————————————— Linked list ———— ———— ———— ———— ———— |1|*->|2|*->|3|*->|4|*->|5|*->NULL ———— ———— ———— ———— ———— My thing: ———————————— ———————————— |1|2|3|4|5|*->|6|7|8|9|a|*->NULL ———————————— ————————————

    Read the article

  • How to copy a structure with pointers to data inside (so to copy pointers and data they point to)?

    - by Kabumbus
    so I have a structure like struct GetResultStructure { int length; char* ptr; }; I need a way to make a full copy of it meaning I need a copy to have a structure with new ptr poinnting on to copy of data I had in original structure. Is It any how possible? I mean any structure I have which contains ptrs will have some fields with its lengths I need a function that would copy my structure coping all ptrs and data they point to by given array of lengthes... Any cool boost function for it? Or any way how to create such function?

    Read the article

  • hash table with chaining method program freezing

    - by Justin Carrey
    I am implementing hash table in C using linked list chaining method. The program compiles but when inserting a string in hash table, the program freezes and gets stuck. The program is below: struct llist{ char *s; struct llist *next; }; struct llist *a[100]; void hinsert(char *str){ int strint, hashinp; strint = 0; hashinp = 0; while(*str){ strint = strint+(*str); } hashinp = (strint%100); if(a[hashinp] == NULL){ struct llist *node; node = (struct llist *)malloc(sizeof(struct llist)); node->s = str; node->next = NULL; a[hashinp] = node; } else{ struct llist *node, *ptr; node = (struct llist *)malloc(sizeof(struct llist)); node->s = str; node->next = NULL; ptr = a[hashinp]; while(ptr->next != NULL){ ptr = ptr->next; } ptr->next = node; } } void hsearch(char *strsrch){ int strint1, hashinp1; strint1 = 0; hashinp1 = 0; while(*strsrch){ strint1 = strint1+(*strsrch); } hashinp1 = (strint1%100); struct llist *ptr1; ptr1 = a[hashinp1]; while(ptr1 != NULL){ if(ptr1->s == strsrch){ cout << "Element Found\n"; break; } else{ ptr1 = ptr1->next; } } if(ptr1 == NULL){ cout << "Element Not Found\n"; } } hinsert() is to insert elements into hash and hsearch is to search an element in the hash. Hash function is written inside hinsert() itself. In the main(), what i am initializing all the elements in a[] to be NULL like this: for(int i = 0;i < 100; i++){ a[i] = NULL; } Help is very much appreciated. Thanks !

    Read the article

  • Fastest way to read/store lots of multidimensional data? (Java)

    - by RemiX
    I have three questions about three nested loops: for (int x=0; x<400; x++) { for (int y=0; y<300; y++) { for (int z=0; z<400; z++) { // compute and store value } } } And I need to store all computed values. My standard approach would be to use a 3D-array: values[x][y][z] = 1; // test value but this turns out to be slow: it takes 192 ms to complete this loop, where a single int-assignment int value = 1; // test value takes only 66 ms. 1) Why is an array so relatively slow? 2) And why does it get even slower when I put this in the inner loop: values[z][y][x] = 1; // (notice x and z switched) This takes more than 4 seconds! 3) Most importantly: Can I use a data structure that is as quick as the assignment of a single integer, but can store as much data as the 3D-array?

    Read the article

  • Java loop and increment problem

    - by user552961
    Can any one tell me what is the problem in my program? String a[],b[]; int c[] = new int[b.length]; for (int j = 0; j < a.length; j++) { for (int k = 0; k < b.length; k++) { if (b[k].equals(a[j])) { c[k]++; } else { c[k] = 0; } } } I have thousands of words stored in a HashMap. Now I want to check in every file that how many time one word occurred from allWords. Can you point out mistake in my program or give me your idea that how I can do it?

    Read the article

  • visual description for data structure

    - by radi
    i have a data structure for my compiler (such as ast) , and i need a method to print it (like ms visio) and verify its contents (i need to verify the contents of the ast nodes) note : i dont want to print it to the console , i am using c++ & qt thanks

    Read the article

  • dictionary/map/key-value pairs data structure in C

    - by morgancodes
    How does one construct and access a set of key-value pairs in C? To use a silly simple example, let's say I want to create a table which translates between an integer and its square root. If I were writing javascript, I could just do this: var squareRoots = { 4: 2, 9: 3, 16: 4, 25: 5 } and then access them like: var squareRootOf25 = squareRoots[5] What's the prettiest way to do this in C? What if I want to use one type of enum as the key and another type of enum as the value?

    Read the article

  • Only add if not already in place

    - by Woppie
    Here's my data structure: var data = [ { id: '1924', info: 'boo' }, { id: '1967', info: 'foo' } ]; The id value should be unique, but the info may not be unique. How would I add new data into the data hash only if the id of the new data is unique? Is the only way to iterate over the whole hash and see if there is such an id already in place? data.push({ id: '1967', info: 'goo-goo' }); //should not be added data.push({ id: '1963', info: 'goo-goo' }); //should be added

    Read the article

  • Data Structure Brushup (Java)

    - by Daddy Warbox
    This should be easy for many of you, but for me it's just another bit of rust needing to be chipped away as I get back into basic Java coding. Using bloody associative arrays for so long in other languages have turned me nice and spoiled. :P My problem is simple: I'm storing a set of objects, each containing a string and a number, in a list. I would like each object inserted into this list to be sorted alphabetically by its string. I would also like to be able to retrieve objects from the list by their string as well. I would like to do this as formally and/or efficiently as possible. Is there something already available in the Java standard libraries for this?

    Read the article

  • What would a compress method do in a hash table?

    - by Bradley Oesch
    For an assignment I have to write the code for a generic Hash Table. In an example Put method, there are two lines: int hash = key.hashCode(); // get the hashcode of the key int index = compress(hash); // compress it to an index I was of the understanding that the hashCode method used the key to return an index, and you would place the key/value pair in the array at that index. But here we "compress" the hash code to get the index. What does this method do? How does it "compress" the hash code? Is it necessary and/or preferred?

    Read the article

  • How to create wordpress-like option table and get values for each row? (PHP-MySQL)

    - by Nacho
    Hi guys. I'm looking to create an options table in my db that makes every record a system option, so i can work with a little number of fields. my db has the following structure: 3 columns named id, name, and value following data is inserted as an example -- id - name - value 1 - uri - www.example.com 2 - sitename - Working it out 3 - base_folder - /folder1/folder2/ 4 - slogan - Just a slogan for the site -- that way i can include a large number of customizable system options very easily the problem is that i don't know how to retrieve them how do i get the value of uri and store it as a var? and better yet, how do i get, for exmaple, values of id 1 and 4 only without making a query each time? (i assume multiple queries are useless and a pretty ugly method) i know the question is pretty basic but i'm lost here. i'd really appreciate your answer! Thanks in advance

    Read the article

  • Multi-key dictionaries (of another kind) in C#?

    - by Matthew Scharley
    Building on this question, is there a simple solution for having a multi-key dictionary where either key individually can be used to identify the value? ie. MultikeyDictionary<TKey1, TKey2, TValue> foo; foo.Add(key1, key2, value); myValue = foo[key1]; // value == myValue foo.Remove(key2); myValue = foo[key1]; // invalid, Exception or null returned

    Read the article

  • List of values as keys for a Map

    - by thr
    I have lists of variable length where each item can be one of four unique, that I need to use as keys for another object in a map. Assume that each value can be either 0, 1, 2 or 3 (it's not integer in my real code, but a lot easier to explain this way) so a few examples of key lists could be: [1, 0, 2, 3] [3, 2, 1] [1, 0, 0, 1, 1, 3] [2, 3, 1, 1, 2] [1, 2] So, to re-iterate: each item in the list can be either 0, 1, 2 or 3 and there can be any number of items in a list. My first approach was to try to hash the contents of the array, using the built in GetHashCode() in .NET to combine the hash of each element. But since this would return an int I would have to deal with collisions manually (two equal int values are identical to a Dictionary). So my second approach was to use a quad tree, breaking down each item in the list into a Node that has four pointers (one for each possible value) to the next four possible values (with the root node representing [], an empty list), inserting [1, 0, 2] => Foo, [1, 3] => Bar and [1, 0] => Baz into this tree would look like this: Grey nodes nodes being unused pointers/nodes. Though I worry about the performance of this setup, but there will be no need to deal with hash collisions and the tree won't become to deep (there will mostly be lists with 2-6 items stored, rarely over 6). Is there some other magic way to store items with lists of values as keys that I have missed?

    Read the article

  • Reading from socket

    - by user363638
    I have data from socket, which is header and message. Header if of 5 bytes, 3rd and 4th is message length. I am reading from socket, can someone suggest me good function, it will return me msg. assuming that i am reading 1024 bytes and it may happen that i have recived only partial data.

    Read the article

< Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >