Feb-25-2019, 06:28 AM
i am thinking about a list to be a stack where i keep a most recently used index. when an index is used or created it gets put on one end. once the stack reaches a configured size, then every time an index is added to the stack, another index at the other end is deleted from the stack to keep it from growing too much.
i started writing some code to do this and quickly realized i needed to decide which end of the list (the [0] end or the [-1] end) would be which. i believe either choice can be made to work but one might be more efficient than the other. any ideas?
i am doing this to create a cache of data lookups that would be slow. the slowness can vary since this thing is general purpose. when the data is found in the cache, that one moves all the way to the "recent" end. when data is not found, it is looked up from a file or database or over the local network or over the internet. the new data is added to the cache at the "recent" end and if the cache has reached its maximum size a data item is deleted from the opposite end. the cache usually will have a dictionary along side.
should the "recent" end be at [0] in the list, or at [-1]. assume a tuple would never be used for this.
i started writing some code to do this and quickly realized i needed to decide which end of the list (the [0] end or the [-1] end) would be which. i believe either choice can be made to work but one might be more efficient than the other. any ideas?
i am doing this to create a cache of data lookups that would be slow. the slowness can vary since this thing is general purpose. when the data is found in the cache, that one moves all the way to the "recent" end. when data is not found, it is looked up from a file or database or over the local network or over the internet. the new data is added to the cache at the "recent" end and if the cache has reached its maximum size a data item is deleted from the opposite end. the cache usually will have a dictionary along side.
should the "recent" end be at [0] in the list, or at [-1]. assume a tuple would never be used for this.