Object Listing Algorithm

Say you have a list of objects. The user uses mostly all the objects when he is working. How can you arrange the list of objects so that the list adapts to the order that users mostly use? What algorithm can you use for this?

EDIT: Many answers suggested counting the number of times an object was used. This does not work, because all objects are used the same way, only in different orders.

+5
source share
10 answers

Inside your object save usedCount. Whenever an object is used, increase this amount. Then you can simply do this:

objects.OrderByDescending(o => o.UsedCount);
+2
source

, , .

, X , .

:

Item       Uses     Order of Use
---------------------------------------
Object X   10       1,2,3,1,2,1,3,1,2,2 (18)
Object Y   10       3,1,2,3,3,3,1,3,3,1 (23)
Object Z   10       2,3,1,2,1,2,2,2,2,3 (20)

, , ( ) , .

, . , , .

, , , . , , - .

( ):

Object X   1.8
Object Z   2.0
Object Y   2.3
+1

, . , , .

, w ( - x ), . , > ( - x ).

, , .

0

number_of_views , ++ , . = 0 , number_of_views , 0.

0

, , , "". , , , , . , ..

, .

0

:

class User  
{  
    Collection<Algo> algosUsed = new List<Algo>();     //Won't compile, used for explanation
    ...
}  

Algo :

class Algo  
{  
    int usedCount;  
...  
}  

Algo User, , . . , , , . , User sort, algos User usedCount Algo

0

: ! CODE

, , , .

count_accessed , , 20 // .....

Datastructure , ,

    static TimeSpan TIME_TO_LIVE;
    static int userOrderFactor = 0;

    LinkedList<KeyValuePair<DateTime, int>> myAccessList = new     LinkedList<KeyValuePair<DateTime, int>>();

    private void Access_Detected()
    {
        userOrderFactor++;
        myAccessList.AddLast(new KeyValuePair<DateTime, int>(DateTime.Now, userOrderFactor));
        myPriority += userOrderFactor; // take total count differential, so we dont waste time summing the list
    }



    private int myPriority = 0;
    public int MyPriority
    {
        get
        {
            DateTime expiry = DateTime.Now.Subtract(TIME_TO_LIVE);
            while (myAccessList.First.Value.Key < expiry)
            {
                myPriority += myAccessList.First.Value.Value; // take care of the Total Count 
                myAccessList.RemoveFirst();
            }
            return myPriority;
        }
    }

, ... O (1) BTW...

0

, . spose, , , ... " "... , , , , " ": num_of_uses , , , , var ++.

num_of_uses ++ d.

0

fooobar.com/questions/1043710/...:

, OrderedMultiDictionary .

0

, , , , .

, , , .

When you create your list of objects to display, you start with the one you saved as the most frequently used first object, then search for the object that has the first used object identifier stored on it to display the next.

0
source

All Articles