From 6b19a647504a46203b647f446430a7dc3095dbb0 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Nov 1996 23:14:16 +0000 Subject: [PATCH] flower-1.0.8 --- flower/cursor.cc | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/flower/cursor.cc b/flower/cursor.cc index 2a9f885689..75f607dcaa 100644 --- a/flower/cursor.cc +++ b/flower/cursor.cc @@ -68,27 +68,38 @@ Cursor::operator -( int i ) const return r; } - +/* + warning: can't use Cursor::operator == (Cursor), + since it uses Cursor::operator-(Cursor) + */ template int -Cursor::operator-(Cursor c) const +Cursor::operator-(Cursor rhs) const { - assert(c.list == list); + assert(rhs.list == list); int dif = 0; - Cursor upward(c); - while (upward.ok() && upward.pointer_ != pointer_) { - upward++; + + // search from *this on further up (positive difference) + Cursor c(*this); + while (c.ok() && c.pointer_ != rhs.pointer_) { + c--; dif++; } - if (upward.ok()) - return dif; + if (c.ok()) + goto gotcha; // so, sue me. + + // search in direction of bottom. (negative diff) dif =0; - while (c.ok()&& c.pointer_ != pointer_) { + c=*this; + while (c.ok() && c.pointer_ !=rhs.pointer_) { dif --; - c--; + c++; } assert(c.ok()); + +gotcha: + assert((*this - dif).pointer_ == c.pointer_); return dif; } -- 2.39.5