Skip to content

Commit

Permalink
Internal: Introduce PaperReviewPreference::compare.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 8, 2024
1 parent e64e187 commit c2ede45
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/papercolumns/pc_preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,30 @@ function prepare(PaperList $pl, $visible) {
}
return true;
}
/** @return PaperReviewPreference */
private function sortable_preference(PaperInfo $row) {
if ($this->not_me
&& ($this->editable
? !$this->viewer->allow_view_preference($row)
: !$this->viewer->can_view_preference($row))) {
return [-PHP_INT_MAX, null];
} else {
$pv = $row->preference($this->user)->as_list();
if ($pv[0] === 0 && $pv[1] === null) {
if (!$this->viewer->can_edit_preference_for($this->user, $row)) {
$pv[0] = -PHP_INT_MAX;
} else if ($row->has_conflict($this->user)) {
$pv[0] = $this->editable ? -0.00001 : -PHP_INT_MAX;
}
return PaperReviewPreference::make_sentinel();
}
$pf = $row->preference($this->user);
if (!$pf->exists()) {
if (!$this->viewer->can_edit_preference_for($this->user, $row)) {
return PaperReviewPreference::make_sentinel();
} else if ($row->has_conflict($this->user)) {
return new PaperReviewPreference($this->editable ? -0.00001 : -PHP_INT_MAX, null);
}
return $pv;
}
return $pf;
}
function compare(PaperInfo $a, PaperInfo $b, PaperList $pl) {
list($ap, $ae) = $this->sortable_preference($a);
list($bp, $be) = $this->sortable_preference($b);
if ($ap !== $bp) {
return $ap <=> $bp;
} else if ($ae !== $be) {
if (($ae === null) !== ($be === null)) {
return $ae === null ? 1 : -1;
}
return (int) $ae <=> (int) $be;
} else if ($this->secondary_sort_topic_score) {
return $a->topic_interest_score($this->user) <=> $b->topic_interest_score($this->user);
} else {
return 0;
$cmp = PaperReviewPreference::compare($this->sortable_preference($a), $this->sortable_preference($b));
if ($cmp === 0 && $this->secondary_sort_topic_score) {
$cmp = $a->topic_interest_score($this->user) <=> $b->topic_interest_score($this->user);
}
return $cmp;
}
function reset(PaperList $pl) {
if ($this->show_conflict === null) {
Expand Down
22 changes: 22 additions & 0 deletions src/paperinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function __construct($preference = 0, $expertise = null) {
$this->expertise = $expertise;
}

/** @return PaperReviewPreference */
static function make_sentinel() {
return new PaperReviewPreference(-PHP_INT_MAX, null);
}

/** @return bool */
function exists() {
return $this->preference !== 0 || $this->expertise !== null;
Expand All @@ -27,6 +32,23 @@ function unparse() {
return ($this->preference ?? "0") . unparse_expertise($this->expertise);
}

/** @param PaperReviewPreference $a
* @param PaperReviewPreference $b
* @return -1|0|1 */
static function compare($a, $b) {
if ($a->preference !== $b->preference) {
return $a->preference <=> $b->preference;
} else if ($a->expertise !== $b->expertise) {
$anull = $a->expertise === null;
if ($anull || $b->expertise === null) {
return $anull ? 1 : -1;
}
return $a->expertise <=> $b->expertise;
} else {
return 0;
}
}

/** @param ?int $tv
* @return string */
function unparse_span($tv = null) {
Expand Down

0 comments on commit c2ede45

Please sign in to comment.