unique

How do I remove duplicate items from an array in Perl?

I have an array in Perl: @my_array = ("one","two","three","two","three") How do I remove the duplicates from the array? ...

How can I get the unique values of an array in .net?

Say I've got this array: MyArray(0)="aaa" MyArray(1)="bbb" MyArray(2)="aaa" Is there a .net function which can give me the unique values? I would like something like this as an output of the function: OutputArray(0)="aaa" OutputArray(1)="bbb" ...

Generating unique account numbers - recursive call

Hi i need to generate 9 digit unique account numbers. Here is my pseudocode: function generateAccNo() generate an account number between 100,000,000 and 999,999,999 if the account number already exists in the DB call generateAccNo() /* recursive call */ else return new accout number end if end func...

Algorithm problem: letter combinations

I'm trying to write a piece of code that will do the following: Take the numbers 0 to 9 and assign one or more letters to this number. For example: 0 = N, 1 = L, 2 = T, 3 = D, 4 = R, 5 = V or F, 6 = B or P, 7 = Z, 8 = H or CH or J, 9 = G When I have a code like 0123, it's an easy job to encode it. It will obviously make up the code NL...

Uniq by object attribute in Ruby

What's the most elegant way to select out objects in an array that are unique with respect to one or more attributes? These objects are stored in ActiveRecord so using AR's methods would be fine too. ...

Is the Hash of a GUID unique?

I create a GUID (as a string) and get the Hash of it. Can I consider this Hash to be unique? ...

Should I lock an ISAM table to insert a value into a unique key field?

I have an ISAm table in mySql that was created similar to this: create table mytable ( id int not null auto_increment primary key, name varchar(64) not null ); create unique index nameIndex on mytable (name); I have multiple processes inserting rows into this table. If two processes try to insert the same "name", I want to make sur...

How do I get the unique elements from an array of hashes in Ruby?

I have an array of hashes, and I want the unique values out of it. Calling Array.uniq doesn't give me what I expect. a = [{:a => 1},{:a => 2}, {:a => 1}] a.uniq # => [{:a => 1}, {:a => 2}, {:a => 1}] Where I expected: [{:a => 1}, {:a => 2}] In searching around on the net, I didn't come up with a solution that I was happy with. Fo...

Generating a unique ID in PHP

I'm trying to generate a unique ID in php in order to store user-uploaded content on a FS without conflicts. I'm using php, and at the moment this little snippet is responsible for generating the UID: $id = tempnam (".", ""); unlink($id); $id = substr($id, 2); This code is hideous: it creates a temporary file on the FS and deletes it...

Extracting unique items from a list of mappings

Hello, He're an interesting problem that looks for the most Pythonic solution. Suppose I have a list of mappings {'id': id, 'url': url}. Some ids in the list are duplicate, and I want to create a new list, with all the duplicates removed. I came up with the following function: def unique_mapping(map): d = {} for res in map: ...

MySQL: Select N rows, but with only unique values in one column

Given this data set: ID Name City Birthyear 1 Egon Spengler New York 1957 2 Mac Taylor New York 1955 3 Sarah Connor Los Angeles 1959 4 Jean-Luc Picard La Barre 2305 5 Ellen Ripley Nostromo 2092 6 James T. Kirk Riverside 2233 7 Henry Jones Chica...

How to create a unique index on a NULL column?

I am using SQL Server 2005. I want to constrain the values in a column to be unique, while allowing NULLS. My current solution involves a unique index on a view like so: CREATE VIEW vw_unq WITH SCHEMABINDING AS SELECT Column1 FROM MyTable WHERE Column1 IS NOT NULL CREATE UNIQUE CLUSTERED INDEX unq_idx ON vw_unq (Column...

What's the difference between creating a UNIQUE index as "index" or as "constraint" in SQL Server?

When creating an index over a column that is going to be UNIQUE (but not the primary key of the table), SQL server let's me choose a few options: 1) I can choose for it to be a Constraint or an Index. I'm guessing this means that if I set it as constraint, it won't use it when querying, only when writing. However, the only efficient way...

How To Create A 'Two-Sided' Unique Index On Two Fields?

How can I efficiently create a unique index on two fields in a table like this: create table t (a integer, b integer); where any unique combination of two different numbers cannot appear more than once on the same row in the table. In order words if a row exists such that a=1 and b=2, another row cannot exist where a=2 and b=1 or a=1 a...

How to count unique records and get number of these uniques in table using SQL?

Hi, Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this is an example of large internet mall, where there are shops which sell to one customer, so customer can choose more products from each shop and buy it in one basket. However, I am not sure if there is an...

C# equivalent of std::sort and std::unique

I have a list of integers in C#. I wish to remove duplicates. In C++ I would run it through the std::sort and then std::unique algorithms for a very efficient way of obtaining the unique list. What's the best way to do the same thing in C#? In other words, I'm looking for a more elegant way to do the following code: private static...

SQL Server - How to insert a record and make sure it is unique

Hi Folks, I'm trying to figure out the best way to insert a record into a single table but only if the item doesn't already exist. The KEY in this case is an NVARCHAR(400) field. For this example, lets pretend it's the name of a word in the Oxford English Dictionary / insert your fav dictionary here. Also, i'm guessing i will need to ma...

Getting a unique id from a unix-like system

Hello. I want to get from any Unix-like system (if this is possible) a unique id that will be persistent every time my application runs in the same machine. If it is possible, I want to get the same id from Linux or FreeBSD or Solaris, etc... I don't want to generate a new id for each machine, but get an already existent id, and I prefe...

Select unique XElements (by attribute) with a filter using LinqToXml

I have an XML document looking similar to this: <items> <item cat="1" owner="14">bla</item> <item cat="1" owner="9">bla</item> <item cat="1" owner="14">bla</item> <item cat="2" owner="12">bla</item> <item cat="2" owner="12">bla</item> </items> Now I'd like to get all unique owners (I actually only need the attribute value of the ...

Normalizing a list of items in MSBuild

I am trying to get a list of all unit test assemblies under the root of my project. I can do this as follows: <CreateItem Include="**\bin\**\*.UnitTest.*.dll"> <Output TaskParameter="Include" ItemName="Items"/> </CreateItem> However, this will find the same DLLs multiple times since they exist in multiple sub-directories. Is there ...