From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: Re: [rfh] do I need to use something more complex to do this?
Date: Wed, 10 Apr 2013 11:19:57 -0700 [thread overview]
Message-ID: <7vr4iimenm.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7vk3oao3e5.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Wed, 10 Apr 2013 07:40:18 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> I have set of items with two attributes, <X,Y>, and would like to
> keep them in some data structure in such a way that it is efficient
> to (1) add a new item to the data structure, and (2) pick an item in
> a specific order. There can be multiple items that share the same
> value for X, or Y, or both X and Y, and it does not matter in what
> order items comes out among those that share the same <X,Y>.
>
> The type of X is totally ordered. The type of Y also usually is, but
> Y can take a special value U(nspecified).
>
> Now on to the "specific" order I want to pick an item. I'd like to
> take the item with the largest value of Y in general, and tiebreaking
> on the value of X which also I prefer to take from larger to smaller.
>
> But with a twist.
>
> When I am picking an item <X=n,Y=m>, there should be no item
> remaining in the data store with a value of Y that is smaller than m
> (duplicates are allowed, so there can still be items with Y=m), and
> also when I am picking <X=n,Y=m>, there should be no item with
> Y=Unspecified that has a value of X that is equal or smaller than n.
>
> E.g. if I have these 6 items (ignore the lines between the items for
> now):
>
> <104,U>--<105,U>--<106,4>
> /
> <101,U>--<100,U>--<102,3>--<104,4>
>
> I would want to pick them up in this order:
>
> <106,4> <105,U> <104,U> <104,4> <102,3> <101,U> <100,U>
Note that with the above specification, a possible solution is to
show all the items with Y=Unspecified before showing others, but
that would not be ideal for the intended use case; pretending Y=U as
if Y=max_range is not a usable workaround.
This is "I create a stream of items with specified Y in descending
order. There are some items with Y=Unspecified and I want to find
appropriate places to mix the latter into that stream".
Because the desired ordering is not a total order, I need to go
to the "pair of priority list" route, I think.
>
> I see how this can easily be done by using a two priority lists,
> i.e. one for items with Y=Unspecified that is sorted by X, and the
> other for all other items that is sorted by <Y,X>. Peek the top of
> both, and pick the top of the former until its X is smaller than the
> value of X of the top of the latter, otherwise pick the top of the
> latter. I am wondering if I can use less complex data structure,
> like a single ordered sorted array, with a clever comparison
> function.
>
> For the curious, the items in the above picture represents commits,
> and lines are ancestry chains between them. I am thinking how we can
> extend the still_interesting() function with an optional generation
> number.
prev parent reply other threads:[~2013-04-10 18:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-10 14:40 [rfh] do I need to use something more complex to do this? Junio C Hamano
2013-04-10 15:23 ` Andreas Ericsson
2013-04-10 18:19 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vr4iimenm.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.