Comments (17)
Here are what I have in mind:
ArrayStore
is obvisouly easily sortable ;NullStore
has the method and it should do nothing ;JsonFileStore
is sortable and the data is written in the file after the sort ;CachedStore
is sortable and just call the delegated storesort()
method ;
I'm not sure about the others (PhpRedisStore
, PredisStore
, RiakStore
), do you have an idea?
from key-value-store.
Sounds good! I don't know about the others, did you research whether they support anything like that?
from key-value-store.
I never worked with Riak but it seems not possible (http://stackoverflow.com/questions/7601997/how-to-sort-order-data-in-riak).
In Redis (PhpRedis and Preedis) it seems possible (http://stackoverflow.com/questions/5780365/redis-how-can-i-sort-my-hash-by-keys) but need a bit of changes in the store, like probably creating a single key containing all the store data.
I'll think about it a bit more.
from key-value-store.
Actually it seems possible to list all the keys in Riak: http://www.paperplanes.de/2011/12/13/list-all-of-the-riak-keys.html. We could store these keys in an array in the store and sort them on sort()
call. What do you think?
from key-value-store.
Probably that's better, yes. What about changing the interface to:
interface SortedStore extends KeyValueStore
{
}
This interface could be implemented directly by the stores that support sorting easily. For the others, we could implement a SortingAdapter
that takes another store and sorts the keys returned from getMultiple()
and keys()
. What do you think?
from key-value-store.
However, as a user of the SortedStore
, you lose the power to control the direction of the sorting, which is maybe not optimal. Hm.
from key-value-store.
I think what could be great is SortableStore
: just an interface for stores supporting sort. We could also introduce your idea of SortingAdapter
as a way to sort not sortable stores. We could have something like:
class ArrayStore implements SortableStore, SortingAdapter
{}
class RiakStore implements SortableStore
{
private $sortableAdapter;
public function sort() {
// We inject all the data in the adapter, sort it, and return
}
}
What do you think?
from key-value-store.
Sounds good. However, I think SortingAdapter
should be something like this:
class SortableAdapter implements SortableStore
{
private $innerStore;
private $flags = SORT_REGULAR;
public function sort($flags)
{
$this->flags = $flags;
}
public function keys()
{
$keys = $this->innerStore->keys();
sort($keys, $this->flags);
return $keys;
}
}
from key-value-store.
Hum. I'm not a fan of giving the possibility to use it externaly easily.
Perhaps externalizing the system of SortableAdapter of the stores would be better, don't you think?
from key-value-store.
I don't understand?
from key-value-store.
I mean implementing SortableStore
make me think it's a store usable from a developer point of view. I think it's more an internal system, and shouldn't implement an API interface. But it's not that much a problem :) .
from key-value-store.
The problem is that sorting stores that don't support sorting natively might be quite expensive. So sorting their keys in memory might be a better alternative. Let's talk about this on IRC.
from key-value-store.
For summary:
- Rename
CachedStore
inCachingDecorator
; - Create a
SortableStore
interface for sortable stores ; - Create a
SortableDecorator
with asort()
method that either call the internal storesort()
if it implementsSortableStore
or use an array for an in-memory sort for others ;
SortableDecorator::$flags
should be null by default (no sorting) and be reset to null on set()
so that it behaves the same as any other sorted store, which is only sorted on a call to sort()
.
Is it fine for you?
from key-value-store.
Almost. I would not check whether the inner store implements SortableStore
in SortableDecorator
, that's too complicated. Simply treat the inner store as non-sortable store.
from key-value-store.
- Rename
CachedStore
inCachingDecorator
; - Create a
SortableStore
interface for sortable stores ; - Create a
SortableDecorator
with asort()
method that use an array for an in-memory sort for others ;
SortableDecorator::$flags
should be null by default (no sorting) and be reset to null on set()
so that it behaves the same as any other sorted store, which is only sorted on a call to sort()
.
from key-value-store.
I suppose we can close that now :) .
from key-value-store.
Yes, thanks :)
from key-value-store.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from key-value-store.