The tag has no usage guidance.

learn more… | top users | synonyms

-2
votes
0answers
27 views

Need help in optimizing my arraylist class which contains combination of pair [on hold]

Need help in optimizing my arraylist class which contains combination of pair: import java.util.ArrayList; import java.util.List; public class FieldsProvider2 { private MyObject object; private ...
3
votes
2answers
52 views

Implementing a key-sensitive monad bind for key-value Map

Based on the List monad I set out to define Monad instances for the Map type from Data.Map, to perform chained unions and folds on Maps like lists, but with the efficient sorting and merging of Maps: ...
3
votes
5answers
145 views

Conditionally initializing a string list

I am writing a program that needs to be able to process data from a number of different sources. The sources output data in a variety of formats. So, depending on which source is being used, I need to ...
0
votes
2answers
143 views

Check if list has a list of values

I have been trying to figure out an efficient algorithm that can check if a list of values contains a list of values. Both lists are sorted in ascending order. For example: Check if var ...
1
vote
3answers
144 views

Logic Programming(Unification) vs List Comprehensions (in Functional Programming)

I found this answer on StackOverflow very clear to explain the difference beween the Logic Programming paradigm and the Functional Programming paradigm: The thing that makes logical append ...
1
vote
2answers
132 views

Is python list comprehension using multi-threading or parallelized in any way by default?

When I write... l2 = [my_computation(x) for x in l] ..., I wonder if python is applying my_computation to every x using all cores of my CPU. If not, why ? Is there a simple way to make python ...
1
vote
4answers
76 views

Obtaining lists from an array

Let's say my array contains integers. I'd like to create lists, so that every list contains indexes where a particular value occured in the array. For instance, if the array was 5,0,3,5,2,5,3, we ...
0
votes
3answers
310 views

Is returning a json object instead an array via REST good or bad style?

I am working on my API and would like to return some stats. Those are stored and collected in code, and I can choose my way to return those. My first approach was using hash, so my data looks like: {...
0
votes
1answer
133 views

How to save tuplas values, to later search on it

Scenario I have some values of the type : (Name - Email) From this couples of data, I have to set a ArrayList of "Name" values,something like: |Name1|Name2| --- |NameN| to set a Spinner. (Ordered ...
0
votes
3answers
169 views

Why don't empty iterables in python raise Exceptions when you try to iterate over them [duplicate]

I find this behaviour in Python quite peculiar and I believe it can lead to many bugs especially if you have a function/method that takes in a list and returns another list after carrying out some ...
1
vote
2answers
98 views

Load to list in one loop and then process list in another or do it all at once

I have a dataset full of rows that I must initialize into myclass and then process. I am currently looping through each row in the dataset, initializing a new instance of myclass, then adding that ...
0
votes
1answer
273 views

Efficient way in comparing two lists

I have created two lists of objects: One is records from an xml and the other is records from the database. The rule is check if the record from an xml exist in the database then exclude. I have ...
4
votes
1answer
206 views

JavaScript functional conversion from flat list to tree

I've been going through the RxJS tutorials http://reactivex.io/learnrx/. Almost all of the exercises involve moving from a hierarchical structure to a flat structure so I thought I'd try to do the ...
3
votes
3answers
94 views

Is it odd if Nodes in a LinkedList held references to the List object?

Its like, I want to call .moveToBefore(Node) on a Node object and have the node relocate to before the node passed in. The problem arises if the node passed in is the head node. The List object will ...
2
votes
3answers
213 views

Functional programming: Compare all items in an array

In functional programming, how do I do an equality comparison of all items in an array? I have an array of items that I want to compare, for example for equality. Is it possible to use a fold (also ...
21
votes
5answers
10k views

What's the use of .Any() in a C# List<>?

I've been discussing this with colleagues, and we couldn't figure out what the use is of .Any for any given List<>, in C#. You can check the validity of an element in the array like the ...
4
votes
1answer
74 views

Performance of list concatenation followed by scanning

Consider the following code snippet: -- list_1 = [1, 2, 3] -- list_2 = [4, 5, 6] final_list = list_1 ++ list_2 result = map (+1) final_list Is the time spent by it proportional just to the length ...
0
votes
3answers
765 views

Is there a key/key lookup table type provided in .NET?

It seems like a pretty straightforward thing to add, but I just want to be sure .NET doesn't already provide one and save me from adding unnecessary code: I need a lookup table (like a Dictionary) ...
2
votes
1answer
148 views

When should I use a generator and when a list in Python? [duplicate]

I often find it cleaner to write a generator than to return a list. For example, I prefer def my_func_gen(foo): for i in foo: # Do some stuff that's too complicated for a list or ...
4
votes
2answers
340 views

Is this data model a list or tree?

Using python syntax with below environment diagram, teacher taught us that there are 11 trees(orange boundary) in this diagram, including leaf. It has been taught here, lists are represented as a ...
3
votes
1answer
454 views

Why is iterating through List<T> more expensive than iterating through Array in .NET?

According to the answers in this post, List<T> is backed by an Array. According to this article, list iteration is considerably slower than array iteration. If Lists are arrays 'under the hood',...
3
votes
1answer
169 views

What data type is this?

I have a list of items I am adding to, however this special list will delete anything past a given capacity. Note the order is maintained. For the life of me, I can't think of the name of such a ...
-1
votes
2answers
900 views

'Tuple' vs 'List' operations in python

Only two operations are allowed on tuple, as shown below. Operations like insert / delete at an index is not allowed. I learnt that tuple is an immutable data model. list allows insert and delete ...
-2
votes
3answers
159 views

Is LinkedList an Abstract Data Structure? [duplicate]

This quote is from the book HeadFirst C: A linked list is an example of an abstract data structure. It’s called an abstract data structure because a linked list is general: it can be used to ...
4
votes
3answers
146 views

Is storing data directly in a list node better than storing a pointer to data?

Suppose we have two different doubly-linked list structures: One has content of the node embedded directly in the node: struct Content { // some stuff }; struct Node { struct Node *next; ...
3
votes
1answer
108 views

Why use atomic vectors or matrices in R at all?

In reading Hadley Wickham's Advanced R I learned about the difference between atomic vectors and lists; and matrices/arrays and dataframes. This is something I hadn't really appreciated before, and ...
2
votes
1answer
706 views

Maintain ordered collection by updating as few `order` fields as possible

I'm working on integrating a reorderable lists UI widget with a Meteor.js (MongoDB, in effect) collection: { order: ???, // what type to use here? property1: ..., ... propertyN: ... } Each ...
5
votes
2answers
3k views

Why does java collections not supply a function for the index of max value?

I have been using Collections.max(list) for many projects, but I occasionally want to find the index of that maximum element. I feel silly writing a function to do this for myself in every program I ...
1
vote
2answers
1k views

Why a hashtable? Why not just a non-hashed associative array?

I've been learning about using a hashtable to efficiently check for items in a list without looping through the whole thing, but there's one thing that I don't get: Why hashed keys? It seems like: ...
0
votes
1answer
200 views

Why is first column of list called 0th in so many languages? [duplicate]

If you want first element of list or array you reference it as 0 in many languages (like C or Clojure). Is there are some really good reasons why the programming languages was design this way? In ...
0
votes
1answer
233 views

Design Pattern : Static Array/List in Class Object

I'm a CS alumni, but we didn't learn much by the way of OOP, or Design Patterns. I've heard the phrase C with iostreams and thought it fitting. Anyway that's besides the point. I am just curious about ...
4
votes
1answer
186 views

Tail-recursive implementation of take-while

I am trying to write a tail-recursive implementation of the function take-while in Scheme (but this exercise can be done in another language as well). My first attempt was (define (take-while p xs) ...
1
vote
1answer
94 views

Using a list of tuples vs a list of custom objects

I have a situation where I have several text documents and I want to create a list that contains the words in those documents. But I also need to record several properties of each word. These ...
0
votes
1answer
89 views

Is there a design pattern for updating lists?

I want to modify one list (actually info stored in a database). A person doesn't have access to update every part of the list, but can update and delete parts they do have access to and add whatever ...
0
votes
0answers
47 views

Sorting lists (global vs local)

In my application users have lists. They can either add a new item to their list or add an item from a previous list. The set of all items I'll call G (global) (each user's global list is their own). ...
2
votes
2answers
709 views

Mapping a list of optional values to an optional list of values

I have encountered the following pattern while programming in Haskell (but the pattern could occur in any language supporting lists, option types, and mapping of a function over a list). I have types ...
4
votes
4answers
391 views

Why it is `(cons 1 (cons 2 (cons 3 nil)))` and not `(cons 3 (cons 2 (cons 1 nil)))` for [1,2,3]?

Is there any special reason that to construct list in Scheme you use (cons 1 (cons 2 (cons 3 nil))) instead of (cons 3 (cons 2 (cons 1 nil))) ? While the first seems more obvious because it ...
14
votes
2answers
38k views

Should I use a list or an array?

I'm working on a windows form to calculate UPC for item numbers. I successfully create one that will handle one item number/UPC at a time, now I want to expand and do it for multiple item numbers/...
6
votes
1answer
2k views

Why appending to a list in Scala should have O(n) time complexity?

I am learning Scala at the moment and I just read that the execution time of the append operation for a list (:+) grows linearly with the size of the list. Appending to a list seems like a pretty ...
2
votes
2answers
122 views

Designing a user-defined list to be stored in a relational database - Should I include user index?

By index, I mean, as the user creates the list, each item receives an integer index for its place in that particular list. Since there will be a table of ListItems, I'd prefer to avoid using the name ...
2
votes
3answers
291 views

What language has integrated “list insertion” as part of code *syntax*?

Many programming languages permit natural manipulation of strings, and some languages permit the manipulations of lists too. More often then not (always?), these operations are done as procedure ...
3
votes
3answers
3k views

Best way to choose random element from weighted list

I want to create a simple game. Every so often, a power up should appear. Right now the different kinds of power ups are stored in an array. However, not every power up should appear equally often: ...
0
votes
2answers
230 views

Queues and threading

I am developing a new project where I will be constantly checking a webpage for data and adding this data to a queue for processing. This data will then be removed from the queue and added to a list ...
1
vote
0answers
241 views

Performance of a Skip-List algorithm

Here is a simple code for a randomized skip-list: Coin_Side flip() { if ( random() % 2 == 0 ) return HEADS; else return TAILS; } Note: random() returns an integer that uses ...
1
vote
2answers
169 views

Building a sequential list in languages with cons/linked lists

In languages where cons lists are a major datatype, it is very easy to create a list from last to first by prepending items. When doing processing from some input file, however, one is most likely to ...
9
votes
1answer
595 views

Origin of common list-processing function names

Some higher-order functions for operating on lists or arrays have been repeatedly adopted or reinvented. The functions map, fold[l|r], and filter are found together in several programming ...
1
vote
0answers
315 views

What is the rule on passing around collections? List vs. Ienumerable vs. IQueryable

I do Entity Framework stuff using repository patterns that are passed to the controller to than be called by the client using jquery AJAX.. Is there any basic rules on in what format I should be ...
1
vote
2answers
585 views

Multiple orders in a single list

I have a problem with a ranking system I am using. Scenario: An online game with around 10k players calculates a real time ranking of points when a certain event occurs. Events don't occur that ...
0
votes
1answer
175 views

Show all definitions in Scheme?

I want to see all user-made definitions in a Scheme REPL, both loaded from files and entered at the REPL. Is there any way to "dump all definitions"? E.g. if there is: (define (plusone x) (+ 1 x)...
1
vote
1answer
586 views

Custom Alphabetic Sorting of Array in Java

I have a requirement to read a text file with lines in tag=value format and then output the file with specific tags listed first and the rest sorted alphabetically. The incoming file is randomly ...