Esempio n. 1
0
 //this constructor fills all parameters on their respective fields
 public LFLRUnode(Pagestatus statuss, LFLRUnode previousnode, LFLRUnode datavalue, LFLRUnode nextnode)
 {
     status = statuss;
     prev   = previousnode;
     Data   = datavalue;
     next   = nextnode;
 }
Esempio n. 2
0
 public LFLRUnode(object data, Pagestatus Pstatus)
 {
     status = Pstatus;
     Data   = data;
     prev   = null;
     next   = null;
 }
Esempio n. 3
0
 /// <summary>
 /// To delete the node tempom the list
 /// </summary>
 /// <param name="delenode"></param>
 public void Deletenode(LFLRUnode delenode)
 {
     for (LFLRUnode temp = firstnode; temp != lastnode.next; temp = temp.next)
     {
         if (temp.Data.Equals(delenode.Data))
         {
             if (temp.next == null)
             {
                 lastnode      = lastnode.prev;
                 lastnode.next = null;
                 //temp.prev = null;
             }
             else if (temp.prev == null)
             {
                 firstnode      = firstnode.next;
                 firstnode.prev = null;
                 //temp.next = null;
             }
             else
             {
                 temp.next.prev = temp.prev;
                 temp.prev.next = temp.next;
                 //temp.prev = null;
                 //temp.next = null;
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Moving the Current page to the first position of the list
        /// </summary>
        /// <param name="node"></param>
        public void MoveAtFirsPos(LFLRUnode node)
        {
            if (node.prev == null)
            {
                //Do nothing since the node itself is first node
            }

            else if (node.next == null)
            {
                node.prev.next = null;
                lastnode       = node.prev;
                node.next      = firstnode;
                node.prev      = null;
                firstnode.prev = node;
                firstnode      = node;
            }
            else
            {
                node.prev.next = node.next;
                node.next.prev = node.prev;
                node.next      = firstnode;
                node.prev      = null;
                firstnode.prev = node;
                firstnode      = node;
            }
        }
Esempio n. 5
0
        public bool CheckCleanPage(int noOfStepsTomove)
        {
            bool checkpoint = false;
            int  count      = 0;

            if (IsEmpty())
            {
                checkpoint = false;
            }

            else
            {
                while (noOfStepsTomove > count)
                {
                    for (LFLRUnode temp = lastnode; temp != firstnode.next; temp = temp.prev)
                    {
                        if (temp.status.Equals(Pagestatus.clean))
                        {
                            //Remove node from here
                            checkpoint = true;
                        }
                    }
                    count++;
                }
            }
            return(checkpoint);
        }
Esempio n. 6
0
 /// <summary>
 /// Insert node at the firts position of the list
 /// </summary>
 /// <param name="insertNode"></param>
 public void InsertAtFront(LFLRUnode insertNode)
 {
     if (IsEmpty())
     {
         firstnode = lastnode = insertNode;
     }
     else
     {
         insertNode.next = firstnode;
         firstnode.prev  = insertNode;
         firstnode       = insertNode;
     }
 }
Esempio n. 7
0
        /// <summary>
        /// To search the node in the list
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public LFLRUnode findnode(LFLRUnode node)
        {
            LFLRUnode newnode = new LFLRUnode();

            for (LFLRUnode temp = firstnode; temp != lastnode.next; temp = temp.next)
            {
                if (temp.Data.Equals(node.Data))
                {
                    newnode = temp;
                }
            }
            return(newnode);
        }
Esempio n. 8
0
        //get least recent used block
        public LFLRUnode GetLeastUsedCleanNode(int length)
        {
            LFLRUnode newnode = new LFLRUnode();
            var       count   = 0;

            for (LFLRUnode temp = lastnode; temp != firstnode.prev; temp = temp.prev)
            {
                if (length > count)
                {
                    if (temp.status.Equals(Pagestatus.clean))
                    {
                        newnode = temp;
                    }
                }
                else
                {
                    break;
                }
            }
            return(newnode);
        }
Esempio n. 9
0
        /// <summary>
        /// Search the node in the List
        /// </summary>
        /// <param name="nodetobeSearched"></param>
        /// <returns></returns>
        public bool search(LFLRUnode nodetobeSearched)
        {
            bool checkpoint = false;

            if (IsEmpty())
            {
                checkpoint = false;
            }

            else
            {
                for (LFLRUnode temp = firstnode; temp != lastnode.next; temp = temp.next)
                {
                    if (temp.Data.Equals(nodetobeSearched.Data))
                    {
                        checkpoint = true;
                    }
                }
            }
            return(checkpoint);
        }
Esempio n. 10
0
 /// <summary>
 /// Initialization of the list
 /// </summary>
 /// <param name="listname"></param>
 public cache(string listname)
 {
     name      = listname;
     firstnode = null;
     lastnode  = null;
 }
Esempio n. 11
0
 // returns entire list
 public LFLRUnode(Pagestatus statuss, LFLRUnode datavalue)
     : this(statuss, null, datavalue, null)
 {
 }
Esempio n. 12
0
        public static void Main()
        {
            double mediumValue; //var will determine the range of MRU and LRU.
            int    totalsize;   //hold the user inputed cache size
            int    np = 0, pageCount = 0, pagehit = 0, pagefault = 0, distinctpages = 0;

            Console.WriteLine("Algorithm: LFLRU");
            Console.WriteLine("Cache size:");
            totalsize   = int.Parse(Console.ReadLine());//reads user inputed cache size
            mediumValue = totalsize / 2;
            //check whole and double number, if it is whole number then do nothing otherwise it makes whole number with ceiling function.
            if (Math.Floor(mediumValue) != mediumValue)
            {
                mediumValue = Math.Ceiling(mediumValue);
            }
            LFLRUnode node;                                             // temporary node

            using (StreamReader r = new StreamReader("D:\\sprite.trc")) // give file directory here, reads file based on this directory
            {
                cache  newlist = new cache();
                string refpage;

                while ((refpage = r.ReadLine()) != null)                      // reads entire lines included within file
                {
                    var    distinguishedpageNPageStatus = refpage.Split(','); //splits input string by , and convert this into array
                    object data = distinguishedpageNPageStatus[1];

                    if (distinguishedpageNPageStatus[0].Trim() == "0")
                    {
                        node = new LFLRUnode(data, Pagestatus.clean); // creates new instance
                    }
                    else
                    {
                        node = new LFLRUnode(data, Pagestatus.dirty);
                    }
                    pageCount++;
                    //if page is find in the list
                    if (newlist.search(node))
                    {
                        //Find that particular node in the list
                        LFLRUnode CurrentPage = newlist.findnode(node);
                        //Move  Current page at the begining of the list
                        newlist.MoveAtFirsPos(CurrentPage);
                    }
                    //page in not in the list
                    else
                    {
                        np++;
                        //admit the newly acccessed block to the MRU list till there is no more free slot
                        if (np <= totalsize)
                        {
                            newlist.InsertAtFront(node);
                            //    newlist.showstatus();
                        }
                        //promote the newly accessed
                        else
                        {
                            int noOfStepsTomove = totalsize - Convert.ToInt32(mediumValue);
                            if (newlist.CheckCleanPage(noOfStepsTomove))
                            {
                                //get least used clean page
                                var cleanBlock = newlist.GetLeastUsedCleanNode(noOfStepsTomove);
                                //Remove clean node
                                newlist.Deletenode(cleanBlock);
                                //Add new at the front
                                newlist.InsertAtFront(node);
                            }
                            else
                            {
                                //Remove Last node from list
                                newlist.RemoveLastNode();
                                //Add new one at the front
                                newlist.InsertAtFront(node);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Total Number of Pages:" + pageCount);
            Console.WriteLine("Total Number of distinct Pages:" + distinctpages);
            Console.WriteLine("Totol Number Of Page fault:" + pagefault);
            Console.WriteLine("Totol Number Of Page Hit:" + pagehit);
            Console.ReadLine();
        }
Esempio n. 13
0
 public void RemoveLastNode()
 {
     lastnode      = lastnode.prev;
     lastnode.next = null;
 }
Esempio n. 14
0
 public LFLRUnode()
 {
     Data = null;
     prev = null;
     next = null;
 }