Coder Social home page Coder Social logo

Comments (17)

tgalopin avatar tgalopin commented on May 27, 2024

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 store sort() method ;

I'm not sure about the others (PhpRedisStore, PredisStore, RiakStore), do you have an idea?

from key-value-store.

webmozart avatar webmozart commented on May 27, 2024

Sounds good! I don't know about the others, did you research whether they support anything like that?

from key-value-store.

tgalopin avatar tgalopin commented on May 27, 2024

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.

tgalopin avatar tgalopin commented on May 27, 2024

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.

webmozart avatar webmozart commented on May 27, 2024

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.

webmozart avatar webmozart commented on May 27, 2024

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.

tgalopin avatar tgalopin commented on May 27, 2024

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.

webmozart avatar webmozart commented on May 27, 2024

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.

tgalopin avatar tgalopin commented on May 27, 2024

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.

webmozart avatar webmozart commented on May 27, 2024

I don't understand?

from key-value-store.

tgalopin avatar tgalopin commented on May 27, 2024

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.

webmozart avatar webmozart commented on May 27, 2024

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.

tgalopin avatar tgalopin commented on May 27, 2024

For summary:

  • Rename CachedStore in CachingDecorator ;
  • Create a SortableStore interface for sortable stores ;
  • Create a SortableDecorator with a sort() method that either call the internal store sort() if it implements SortableStore 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.

webmozart avatar webmozart commented on May 27, 2024

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.

tgalopin avatar tgalopin commented on May 27, 2024
  • Rename CachedStore in CachingDecorator ;
  • Create a SortableStore interface for sortable stores ;
  • Create a SortableDecorator with a sort() 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.

tgalopin avatar tgalopin commented on May 27, 2024

I suppose we can close that now :) .

from key-value-store.

webmozart avatar webmozart commented on May 27, 2024

Yes, thanks :)

from key-value-store.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.