data-structures

aligning the xml document

i'm inserting the data into an xml file using php domdocument. however when i open the xml file, the data is displayed in a single line: <?xml version="1.0"?> <root><activity>swimming</activity><activity>jogging</activity></root> how do i align it programmatically like this? <?xml version="1.0"?> <root> <activity>swimming</activity...

Java data structure question

Hi, I was wondering what would be the best data structure(s) to use for the following scenario: I have 2 object types A and B A may contain many instances of B A.name is unique. B.name is unique within it's instance of A (though not globally unique) I would like to be able to provide accessor methods such as getA(String aName) retur...

How are elements stored in containers in .Net?

Hi How are elements stored in containers in .Net? For example, a C++ vector stores in sequential order, while List doesn't. How are they implemented for .Net containers (Array, ArrayList, ...)? Thanks. ...

Problem printing out linked-list

I am trying to create my own datatype that is like a vector or an array. I am having troubles with my print function; When I go to print the list, it only prints the last item in the list. // LinkedListClass.cpp : Defines the entry point for the console application. #include "stdafx.h" #include <iostream> class Node { public: int va...

What is an appropriate data structure for a two-way name ↔ id relation?

I have a list of student names and their id. Sometimes I need to search name using id, sometimes I need to search id using name. If using array[id] = name, then it is quick to find a name using an id but slow to find the id using a name. If using hash{name} = id, then it is quick to find the id using a name but slow to find the name f...

Java & Data Structures: Can someone discuss theses data structures one by one for this question?

Which Java collection class can be used to maintain the entries in the order in which they were last accessed? Choose one answer. a. java.util.HashSet b. java.util.LinkedHashMap c. java.util.Hashtable d. java.util.Vector e. None of these ...

Extending protocols for custom Java classes, maps and sequences in Clojure

I have created a protocol in Clojure 1.2 that handles my own Java classes and has default handling for a generic java.lang.Object. The code looks something like: (extend-protocol PMyProtocol my.java.ClassName (protocol-function [c] "My Java class result") java.lang.Object (protocol-function [c] "Default object r...

DB Design: best practices to hierarchical structure.

I'll try to expose as clear as possible ;) Well, i need to store some data that can be linket to themselves as the parent > child relationship, with no-limit deep. My first try was: entry_id | parent_id | value 1 | NULL | Foo //foo is the grand parent 2 | 1 | Bar //bar is child of Foo 3 | 1 ...

Map two values to one object

I am trying to write a function in C# that will take two small int values (range 0-3) and return a Color object based on those values. The problem is that there is no way to programmatically determine the color from the two values, they are specific to a type of LED and must be hardcoded. The simplest way I can think of would be a mass...

data structure for tabular data

I need to represent data (retreived from a db) representing tabular data (with an x and y axis): The pair (x,y) has data (an object) associated with it. What would be the most semantically correct way to represent this structure? Of course I have to retrieve the data by indexing either by x or by y, but a symmetric way to represent th...

C++ Data structures API Questions

What C++ library provides Data structures API that match the ones provided by java.util.* as much as possible. Specifically, I am looking for the following DS and following Utility Functions:- **DS**: Priority Queue, HashMap, TreeMap, HashSet, TreeSet, ArrayList, String most importantly. **Utility**: Arrays.* , Collections.*, Rege...

Data structure for matching sets

I have an application where I have a number of sets. A set might be {4, 7, 12, 18} unique numbers and all less than 50. I then have several data items: 1 {1, 2, 4, 7, 8, 12, 18, 23, 29} 2 {3, 4, 6, 7, 15, 23, 34, 38} 3 {4, 7, 12, 18} 4 {1, 4, 7, 12, 13, 14, 15, 16, 17, 18} 5 {2, 4, 6, 7, 13, 15} Data items 1, 3 and 4 match the set beca...

storing tree element in jQuery

I have developed a tree menu using jQuery api. But all my tree elements are hard coded. I want to store the tree elements in a data structure and create the tree dynamically. Does jQuery has any data structure like linked list or sth or do I have to code my own data structure ? ...

How can I better represent user permissions?

In my system I have a single class with a load of (20?) final booleans defining the permissions this user type has. What is a better way to do this? I'm sure there's lots of examples about this but I don't know the keywords. ...

MySQL - Is using TEXT for potentially small strings overkill?

One of the things that always worries me in MySQL is that my string fields will not be large enough for the data that need to be stored. The PHP project I'm currently working on will need to store strings, the lengths of which may vary wildly. Not being familiar with how MySQL stores string data, I'm wondering if it would be overkill to...

How to store ordered items which often change position in DB

I need to be able to store a large list of ordered items in the DB. So far that's straight-forward: ID Position OtherFields 1 45 ... 2 4736 ... 3 514 ... ... In queries, I always need to get just a few items (filtered based on OtherFields) but in the correct order. Easy as well, putting an index on Position...

How do I implement a Bipartite Graph in Java?

UPDATE Some answers so far have suggested using an adjacency list. How would an adjacency list look like in Java? ... no pointers right :) I'm trying to implement a Bipartite Graph in Java to sort into 2 groups information from a file. I found this example and it actually does the job: http://users.skynet.be/alperthereal/source_file...

What are the differences between the various boost ublas sparse vectors?

In boost::numeric::ublas, there are three sparse vector types. I can see that the mapped_vector is essentially an stl::map from index to value, which considers all not-found values to be 0 (or whatever is the common value). But the documentation is sparse (ha ha) on information about compressed_vector and coordinate_vector. Is anyone ...

How can I group a large dataset

I have simple text file containing two columns, both integers 1 5 1 12 2 5 2 341 2 12 and so on.. I need to group the dataset by second value, such that the output will be. 5 1 2 12 1 2 341 2 Now the problem is that the file is very big around 34 Gb in size, I tried writing a python script to group them into a dictionary with val...

What questions should be asked before making a .Net application ready for communicating with SAP?

Hi, In one of the projects I work for we are asked for to investigate the possibilities of our application's communication with SAP applications. As a person who does not have any experience with SAP, what steps should I follow and what questions should I ask to come out with a useful report? Can you recommend me a road map to achiev...