get() private method

private get ( key ) : V
return V
 public void run(K key, System.Action <V> callback)
 {
     if (!awaitingCallbacks.ContainsKey(key))
     {
         awaitingCallbacks [key] = new List <System.Action <V> > ();
         awaitingCallbacks [key].Add(callback);
     }
     else
     {
         awaitingCallbacks [key].Add(callback);
     }
     if (!activeDownloads.Contains(key))           //don't download again, wait for previous download to finish and execute callback
     {
         if (cache.contains(key))
         {
             executeQueuedCallbacks(key, cache.get(key));
         }
         else
         {
             activeDownloads.Add(key);
             owner.StartCoroutine(download(key, result => {
                 cache.add(key, result);
                 activeDownloads.Remove(key);
                 executeQueuedCallbacks(key, cache.get(key));
             }));
         }
     }
 }
Example #2
0
        public static Image GetAppImage(string path, IconSize size)
        {
            var key = path + "." + size.Size();

            if (imageCache.get(key) is Image image)
            {
                return(image);
            }

            return(GetCachedIconImage(key,
                                      () => GetFileIconFromExecutable(path, size),
                                      () => IconForName("notfound", size)));
        }
Example #3
0
        public void LRUCacheTest()
        {
            LRUCache lru = new LRUCache(5);

            lru.set(1, 4);
            lru.set(2, 4);
            lru.set(3, 4);
            lru.set(4, 4);
            lru.set(1, 69);
            lru.set(5, 4);
            lru.set(6, 23);

            Assert.Equal(lru.get(1), -1);
            Assert.Equal(lru.get(6), 23);
        }
Example #4
0
 /// <summary>
 /// Set the appropriate timeout per website
 /// returns the host that was evicted from timeout
 /// </summary>
 /// <param name="hostname"></param>
 public void markHostForTimeout(string hostname)
 {
     if (webpageHosts.get(hostname) == null)
     {
         webpageHosts.put(hostname, new ThreadSleeper(MIN_THREAD_SLEEP));
     }
     else
     {
         ThreadSleeper sleeper = webpageHosts.get(hostname);
         if (sleeper.getTimeoutLimit() < MAX_THREAD_SLEEP)
         {
             sleeper.addTenSeconds();
         }
         sleeper.restart();
     }
 }
Example #5
0
        static void testLRU()
        {
            LRUCache cache = new LRUCache(2);

            cache.set(1, 10);
            cache.set(2, 20);
            Console.WriteLine("Value for the key: 1 is " + cache.get(1)); // Should return 10

            cache.set(3, 30);                                             // Evicts key 2 and store a key (3) with value 30 in the cache.

            Console.WriteLine("Value for the key: 2 is " + cache.get(2)); // Should return -1 (not found)

            cache.set(4, 40);                                             // Evicts key 1 and store a key (4) with value 40 in the cache.
            Console.WriteLine("Value for the key: 1 is " + cache.get(1)); // Should return -1 (not found)
            Console.WriteLine("Value for the key: 3 is " + cache.get(3)); // Should return 30
            Console.WriteLine("Value for the key: 4 is " + cache.get(4)); // Should return 40
        }
Example #6
0
    public static void Main(string[] args)
    {
        int noOfTC = Convert.ToInt32(Console.ReadLine());

        for (int t = 0; t < noOfTC; ++t)
        {
            ////int num = Convert.ToInt32(Console.ReadLine());
            //string[] s1 = Console.ReadLine().Split(' ');
            ////int[] arr = Array.ConvertAll(s1, int.Parse);
            ////string str = Console.ReadLine();
            //int i = 0;
            LRUCache lru = new LRUCache(3);
            lru.set(1, 3);
            lru.set(2, 4);
            Console.WriteLine(lru.get(2));
            lru.set(5, 6);
            lru.set(1, 8);
            Console.WriteLine(lru.get(1));
            lru.set(12, 14);
            Console.WriteLine(lru.get(2));
        }
        Console.ReadLine();
    }
Example #7
0
    public IEnumerator downloadAndCreateTexture(string imagePath, System.Action <Texture2D> callback)
    {
        if (textureCache.contains(imagePath))
        {
            Debug.LogFormat("Cache contains {0}", imagePath);
            callback(textureCache.get(imagePath));
            yield return(null);
        }
        else
        {
            Debug.LogFormat("Cache does not contain {0}", imagePath);

            yield return(API.downloadAndCreateTexture(imagePath, texture => {
                textureCache.add(imagePath, texture);
                callback(texture);
            }));
        }
    }
Example #8
0
        private static Image GetCachedIconImage(string key, Func <Icon> iconGetter, Func <Image> defaultHandler)
        {
            if (!(iconCache.get(key) is Icon icon))
            {
                icon = iconGetter();

                if (icon is null)
                {
                    Log.error("Cannot get icon for " + key);
                    return(defaultHandler());
                }

                iconCache.put(key, icon);
            }
            var image = icon.ToBitmap();

            imageCache.put(key, image);
            return(image);
        }
    void SelectActiveGlows()
    {
        m_NumActiveGlows = 0;

        if (Camera.main == null)
        {
            return;
        }

        Camera     cam      = Camera.main;
        Vector3    camPos   = cam.transform.position;
        S_CacheRec visRec   = new S_CacheRec();
        float      currTime = Time.time;

        foreach (ScreenSpaceGlowEmitter curr in ScreenSpaceGlowEmitter.ms_Instances)
        {
            Vector3 glowPos = curr.transform.position;

            if (Vector3.Distance(camPos, glowPos) > curr.m_MaxVisDist)
            {
                continue;
            }

            Vector3 viewportPos = cam.WorldToViewportPoint(glowPos);

            if (viewportPos.z < 0)
            {
                continue;
            }

            if (viewportPos.x < 0 || viewportPos.x > 1 ||
                viewportPos.y < 0 || viewportPos.y > 1)
            {
                continue;
            }

            if (m_NumActiveGlows >= MAX_GLOWS)
            {
                return;
            }

            bool isBlocked      = false;
            bool updateVisState = true;

            if (m_GlowsVisCache.get(curr.m_InstanceID, ref visRec))
            {
                float age = currTime - visRec.m_QueryTime;

                MFDebugUtils.Assert(age >= 0.0f);

                if (age <= m_MaxVisQueryResultAge)
                {
                    isBlocked      = visRec.m_IsBlocked;
                    updateVisState = false;
                }
            }

            if (updateVisState)
            {
                Vector3 dir = glowPos - camPos;

                isBlocked = Physics.Raycast(camPos, dir, 1, curr.m_ColLayerMask);

                visRec.m_IsBlocked = isBlocked;
                visRec.m_QueryTime = currTime;

                m_GlowsVisCache.add(curr.m_InstanceID, visRec);
            }

            if (!isBlocked)
            {
                Vector3 toViewer = camPos - glowPos;
                Vector3 ldir     = curr.transform.forward;
                float   dist     = toViewer.magnitude;

                toViewer.Normalize();

                float dirFadeout   = RemapValue(Mathf.Clamp01(Vector3.Dot(toViewer, ldir)), Mathf.Cos(curr.m_ConeAngle * Mathf.Deg2Rad / 2), 1, 0, 1);
                float ndist        = Mathf.Clamp01(dist / curr.m_MaxVisDist);
                float intensityMod = dirFadeout * (1 - ndist * ndist);

                //Debug.Log(intensityMod);

                if (intensityMod > 0.001f)
                {
                    m_ActiveGlows[m_NumActiveGlows++] = curr;
                }
            }
        }
    }