123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <nvbio/basic/types.h>
- #include <nvbio/basic/cache.h>
- using namespace nvbio;
- struct CacheManager
- {
-
- CacheManager() : m_size(0) {}
-
- bool acquire(const uint32 i)
- {
- if (m_size >= 100u)
- return false;
- ++m_size;
- return true;
- }
-
- void release(const uint32 i)
- {
- --m_size;
- }
-
- bool low_watermark() const
- {
- return (m_size < 75u);
- }
- uint32 m_size;
- };
- int cache_test()
- {
- printf("cache test... started\n");
- CacheManager manager;
- LRU<CacheManager> cache( manager );
- for (uint32 i = 0; i < 1000; ++i)
- {
- cache.pin(i);
- cache.unpin(i);
- }
- printf(" test overflow... started\n");
- bool overflow = false;
- try
- {
- for (uint32 i = 0; i < 200; ++i)
- cache.pin(i);
- }
- catch (cache_overflow)
- {
- overflow = true;
- }
- if (overflow == false)
- printf(" error: overflow was expected, but did not occurr!\n");
- else
- printf(" test overflow... done\n");
- printf("cache test... done\n");
- return 0u;
- }
|