diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java index c54ca5d..7ea0f81d5 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientFullScreenTest.java
@@ -309,12 +309,11 @@ // still there. DOMUtils.clickNode(this, mContentViewCore, CUSTOM_FULLSCREEN_CONTROL_ID); mContentsClient.waitForCustomViewShown(); - View customView = mContentsClient.getCustomView(); - assertKeepScreenOnActive(customView, true); + assertKeepScreenOnActive(mTestContainerView, true); // Pause the video and the power save blocker is gone. DOMUtils.pauseMedia(getWebContentsOnUiThread(), VIDEO_ID); - assertWaitForKeepScreenOnActive(customView, false); + assertWaitForKeepScreenOnActive(mTestContainerView, false); // Exit fullscreen and the power save blocker is still gone. DOMUtils.exitFullscreen(getWebContentsOnUiThread()); @@ -340,7 +339,7 @@ // still there. DOMUtils.exitFullscreen(getWebContentsOnUiThread()); mContentsClient.waitForCustomViewHidden(); - assertKeepScreenOnActive(mTestContainerView, true); + assertKeepScreenOnActive(customView, true); } private void tapPlayButton() throws Exception { @@ -402,8 +401,8 @@ } private boolean getKeepScreenOnOnUiThread(View view) { - // The power save blocker is added to a child anchor view, - // so we need to traverse the hierarchy. + // The power save blocker is added to the container view. + // Search the view hierarchy for it. if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) {
diff --git a/base/i18n/time_formatting.cc b/base/i18n/time_formatting.cc index fde255fa..3f560ee5 100644 --- a/base/i18n/time_formatting.cc +++ b/base/i18n/time_formatting.cc
@@ -12,6 +12,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "third_party/icu/source/i18n/unicode/datefmt.h" +#include "third_party/icu/source/i18n/unicode/dtitvfmt.h" #include "third_party/icu/source/i18n/unicode/dtptngen.h" #include "third_party/icu/source/i18n/unicode/fmtable.h" #include "third_party/icu/source/i18n/unicode/measfmt.h" @@ -81,6 +82,17 @@ return UMEASFMT_WIDTH_COUNT; } +const char* DateFormatToString(DateFormat format) { + switch (format) { + case DATE_FORMAT_YEAR_MONTH: + return UDAT_YEAR_MONTH; + case DATE_FORMAT_MONTH_WEEKDAY_DAY: + return UDAT_MONTH_WEEKDAY_DAY; + } + NOTREACHED(); + return UDAT_YEAR_MONTH_DAY; +} + } // namespace string16 TimeFormatTimeOfDay(const Time& time) { @@ -141,6 +153,12 @@ return TimeFormat(formatter.get(), time); } +string16 TimeFormatMonthAndYear(const Time& time) { + icu::SimpleDateFormat formatter = + CreateSimpleDateFormatter(DateFormatToString(DATE_FORMAT_YEAR_MONTH)); + return TimeFormat(&formatter, time); +} + string16 TimeFormatFriendlyDateAndTime(const Time& time) { std::unique_ptr<icu::DateFormat> formatter( icu::DateFormat::createDateTimeInstance(icu::DateFormat::kFull)); @@ -191,6 +209,25 @@ return base::string16(formatted.getBuffer(), formatted.length()); } +string16 DateIntervalFormat(const Time& begin_time, + const Time& end_time, + DateFormat format) { + UErrorCode status = U_ZERO_ERROR; + + std::unique_ptr<icu::DateIntervalFormat> formatter( + icu::DateIntervalFormat::createInstance(DateFormatToString(format), + status)); + + icu::FieldPosition pos = 0; + UDate start_date = static_cast<UDate>(begin_time.ToDoubleT() * 1000); + UDate end_date = static_cast<UDate>(end_time.ToDoubleT() * 1000); + icu::DateInterval interval(start_date, end_date); + icu::UnicodeString formatted; + formatter->format(&interval, formatted, pos, status); + return string16(formatted.getBuffer(), + static_cast<size_t>(formatted.length())); +} + HourClockType GetHourClockType() { // TODO(satorux,jshin): Rework this with ures_getByKeyWithFallback() // once it becomes public. The short time format can be found at
diff --git a/base/i18n/time_formatting.h b/base/i18n/time_formatting.h index f8d616f..0fb6529 100644 --- a/base/i18n/time_formatting.h +++ b/base/i18n/time_formatting.h
@@ -37,6 +37,15 @@ DURATION_WIDTH_NUMERIC // "3:07" }; +// Date formats from third_party/icu/source/i18n/unicode/udat.h. Add more as +// necessary. +enum DateFormat { + // November 2007 + DATE_FORMAT_YEAR_MONTH, + // Tuesday, 7 November + DATE_FORMAT_MONTH_WEEKDAY_DAY, +}; + // Returns the time of day, e.g., "3:07 PM". BASE_I18N_EXPORT string16 TimeFormatTimeOfDay(const Time& time); @@ -62,6 +71,9 @@ // Returns a numeric date and time such as "12/13/52 2:44:30 PM". BASE_I18N_EXPORT string16 TimeFormatShortDateAndTime(const Time& time); +// Returns a month and year, e.g. "November 2007" +BASE_I18N_EXPORT string16 TimeFormatMonthAndYear(const Time& time); + // Returns a numeric date and time with time zone such as // "12/13/52 2:44:30 PM PST". BASE_I18N_EXPORT string16 @@ -99,6 +111,12 @@ TimeDurationFormatWithSeconds(const TimeDelta time, const DurationFormatWidth width); +// Formats a date interval into various formats, e.g. "2 December - 4 December" +// or "March 2016 - December 2016". See DateFormat for details. +BASE_I18N_EXPORT string16 DateIntervalFormat(const Time& begin_time, + const Time& end_time, + DateFormat format); + // Gets the hour clock type of the current locale. e.g. // k12HourClock (en-US). // k24HourClock (en-GB).
diff --git a/base/i18n/time_formatting_unittest.cc b/base/i18n/time_formatting_unittest.cc index e57ac3b..06cd772 100644 --- a/base/i18n/time_formatting_unittest.cc +++ b/base/i18n/time_formatting_unittest.cc
@@ -188,6 +188,8 @@ EXPECT_EQ(ASCIIToUTF16("4/30/11, 3:42:07 PM ") + GetShortTimeZone(time), TimeFormatShortDateAndTimeWithTimeZone(time)); + EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time)); + EXPECT_EQ(ASCIIToUTF16("Saturday, April 30, 2011 at 3:42:07 PM"), TimeFormatFriendlyDateAndTime(time)); @@ -215,6 +217,7 @@ TimeFormatShortDateAndTime(time)); EXPECT_EQ(ASCIIToUTF16("30/04/2011, 15:42:07 ") + GetShortTimeZone(time), TimeFormatShortDateAndTimeWithTimeZone(time)); + EXPECT_EQ(ASCIIToUTF16("April 2011"), TimeFormatMonthAndYear(time)); EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011 at 15:42:07"), TimeFormatFriendlyDateAndTime(time)); EXPECT_EQ(ASCIIToUTF16("Saturday, 30 April 2011"), @@ -314,5 +317,24 @@ TimeDurationFormatWithSeconds(delta, DURATION_WIDTH_NUMERIC)); } +TEST(TimeFormattingTest, TimeIntervalFormat) { + test::ScopedRestoreICUDefaultLocale restore_locale; + i18n::SetICUDefaultLocale("en_US"); + + const Time::Exploded kTestIntervalEndTimeExploded = { + 2011, 5, 6, 28, // Sat, Apr 30, 2012 + 15, 42, 7, 0 // 15:42:07.000 + }; + + Time begin_time; + EXPECT_TRUE(Time::FromLocalExploded(kTestDateTimeExploded, &begin_time)); + Time end_time; + EXPECT_TRUE(Time::FromLocalExploded(kTestIntervalEndTimeExploded, &end_time)); + + EXPECT_EQ( + WideToUTF16(L"Saturday, April 30 – Saturday, May 28"), + DateIntervalFormat(begin_time, end_time, DATE_FORMAT_MONTH_WEEKDAY_DAY)); +} + } // namespace } // namespace base
diff --git a/chrome/VERSION b/chrome/VERSION index abd1c91..5cb985c 100644 --- a/chrome/VERSION +++ b/chrome/VERSION
@@ -1,4 +1,4 @@ -MAJOR=57 +MAJOR=58 MINOR=0 -BUILD=2987 +BUILD=2988 PATCH=0
diff --git a/chrome/android/java/AndroidManifest.xml b/chrome/android/java/AndroidManifest.xml index 2b0d2c5..247cced0 100644 --- a/chrome/android/java/AndroidManifest.xml +++ b/chrome/android/java/AndroidManifest.xml
@@ -258,7 +258,7 @@ </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> - {% if target_sdk_version|int > 24 %} + {% if target_sdk_version|int > 24 or target_sdk_version == 'O' %} <meta-data android:name="android.app.shortcuts" android:resource="@xml/launchershortcuts" /> {% endif %}
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.cc b/chrome/browser/extensions/api/cookies/cookies_api.cc index 3eb2efb..5c472f2 100644 --- a/chrome/browser/extensions/api/cookies/cookies_api.cc +++ b/chrome/browser/extensions/api/cookies/cookies_api.cc
@@ -146,10 +146,11 @@ // Report an inserted cookie as an "explicit" change cause. All other causes // only make sense for deletions. case net::CookieStore::ChangeCause::INSERTED: - case net::CookieStore::ChangeCause::EXPLICIT_DELETE: - case net::CookieStore::ChangeCause::EXPLICIT_DUPLICATE_IN_BACKING_STORE: - case net::CookieStore::ChangeCause::EXPLICIT_DONT_RECORD: - case net::CookieStore::ChangeCause::EXPLICIT_LAST_ENTRY: + case net::CookieStore::ChangeCause::EXPLICIT: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL: cause = keys::kExplicitChangeCause; break;
diff --git a/chrome/browser/resources/history/externs.js b/chrome/browser/resources/history/externs.js index 123c250..2495b76 100644 --- a/chrome/browser/resources/history/externs.js +++ b/chrome/browser/resources/history/externs.js
@@ -35,8 +35,8 @@ * BrowsingHistoryHandler::QueryComplete() * @typedef {{finished: boolean, * hasSyncedResults: boolean, - * queryEndTime: string, - * queryStartTime: string, + * queryInterval: string, + * queryStartMonth: string, * term: string}} */ var HistoryQuery;
diff --git a/chrome/browser/resources/history/history.js b/chrome/browser/resources/history/history.js index 20814f10..612c9a11 100644 --- a/chrome/browser/resources/history/history.js +++ b/chrome/browser/resources/history/history.js
@@ -631,8 +631,7 @@ $('loading-spinner').hidden = true; this.inFlight_ = false; this.isQueryFinished_ = info.finished; - this.queryStartTime = info.queryStartTime; - this.queryEndTime = info.queryEndTime; + this.queryInterval = info.queryInterval; var lastVisit = this.visits_.slice(-1)[0]; var lastDay = lastVisit ? lastVisit.dateRelativeDay : null; @@ -1579,10 +1578,8 @@ createElementWithClassName('h2', 'timeframe')); // TODO(sergiu): Figure the best way to show this for the first day of // the month. - timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF( - 'historyInterval', - this.model_.queryStartTime, - this.model_.queryEndTime))); + timeFrame.appendChild( + document.createTextNode(this.model_.queryInterval)); }; /**
diff --git a/chrome/browser/resources/md_history/app.crisper.js b/chrome/browser/resources/md_history/app.crisper.js index e885e0f..bfae4eef 100644 --- a/chrome/browser/resources/md_history/app.crisper.js +++ b/chrome/browser/resources/md_history/app.crisper.js
@@ -37,7 +37,7 @@ // Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -Polymer({is:"history-toolbar",properties:{count:{type:Number,value:0,observer:"changeToolbarView_"},itemsSelected_:{type:Boolean,value:false,reflectToAttribute:true},searchTerm:{type:String,observer:"searchTermChanged_",notify:true},spinnerActive:{type:Boolean,value:false},hasDrawer:{type:Boolean,reflectToAttribute:true},isGroupedMode:{type:Boolean,reflectToAttribute:true},groupedRange:{type:Number,reflectToAttribute:true,notify:true},groupedOffset:{type:Number,notify:true},querying:Boolean,hasMoreResults:Boolean,queryStartTime:String,queryEndTime:String,showMenuPromo:Boolean,showSyncNotice:Boolean},get searchField(){return this.$["main-toolbar"].getSearchField()},showSearchField:function(){this.searchField.showAndFocus()},changeToolbarView_:function(){this.itemsSelected_=this.count>0},searchTermChanged_:function(){if(this.searchField.getValue()!=this.searchTerm){this.searchField.showAndFocus();this.searchField.setValue(this.searchTerm)}},onSearchChanged_:function(event){this.searchTerm=event.detail},onInfoButtonTap_:function(){var dropdown=this.$.syncNotice.get();dropdown.positionTarget=this.$$("#info-button-icon");if(dropdown.style.display=="none")dropdown.open()},onClearSelectionTap_:function(){this.fire("unselect-all")},onDeleteTap_:function(){this.fire("delete-selected")},deletingAllowed_:function(){return loadTimeData.getBoolean("allowDeletingHistory")},numberOfItemsSelected_:function(count){return count>0?loadTimeData.getStringF("itemsSelected",count):""},getHistoryInterval_:function(queryStartTime,queryEndTime){return loadTimeData.getStringF("historyInterval",queryStartTime,queryEndTime)},onTodayTap_:function(){if(!this.querying)this.groupedOffset=0},onPrevTap_:function(){if(!this.querying)this.groupedOffset=this.groupedOffset+1},onNextTap_:function(){if(!this.querying)this.groupedOffset=this.groupedOffset-1},isToday_:function(){return this.groupedOffset==0}});(function(){"use strict";Polymer.IronA11yAnnouncer=Polymer({is:"iron-a11y-announcer",properties:{mode:{type:String,value:"polite"},_text:{type:String,value:""}},created:function(){if(!Polymer.IronA11yAnnouncer.instance){Polymer.IronA11yAnnouncer.instance=this}document.body.addEventListener("iron-announce",this._onIronAnnounce.bind(this))},announce:function(text){this._text="";this.async(function(){this._text=text},100)},_onIronAnnounce:function(event){if(event.detail&&event.detail.text){this.announce(event.detail.text)}}});Polymer.IronA11yAnnouncer.instance=null;Polymer.IronA11yAnnouncer.requestAvailability=function(){if(!Polymer.IronA11yAnnouncer.instance){Polymer.IronA11yAnnouncer.instance=document.createElement("iron-a11y-announcer")}document.body.appendChild(Polymer.IronA11yAnnouncer.instance)}})();(function(){var IOS=navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/);var IOS_TOUCH_SCROLLING=IOS&&IOS[1]>=8;var DEFAULT_PHYSICAL_COUNT=3;var HIDDEN_Y="-10000px";var ITEM_WIDTH=0;var ITEM_HEIGHT=1;var SECRET_TABINDEX=-100;Polymer({is:"iron-list",properties:{items:{type:Array},maxPhysicalCount:{type:Number,value:500},as:{type:String,value:"item"},indexAs:{type:String,value:"index"},selectedAs:{type:String,value:"selected"},grid:{type:Boolean,value:false,reflectToAttribute:true},selectionEnabled:{type:Boolean,value:false},selectedItem:{type:Object,notify:true},selectedItems:{type:Object,notify:true},multiSelection:{type:Boolean,value:false}},observers:["_itemsChanged(items.*)","_selectionEnabledChanged(selectionEnabled)","_multiSelectionChanged(multiSelection)","_setOverflow(scrollTarget)"],behaviors:[Polymer.Templatizer,Polymer.IronResizableBehavior,Polymer.IronA11yKeysBehavior,Polymer.IronScrollTargetBehavior],keyBindings:{up:"_didMoveUp",down:"_didMoveDown",enter:"_didEnter"},_ratio:.5,_scrollerPaddingTop:0,_scrollPosition:0,_physicalSize:0,_physicalAverage:0,_physicalAverageCount:0,_physicalTop:0,_virtualCount:0,_physicalIndexForKey:null,_estScrollHeight:0,_scrollHeight:0,_viewportHeight:0,_viewportWidth:0,_physicalItems:null,_physicalSizes:null,_firstVisibleIndexVal:null,_lastVisibleIndexVal:null,_collection:null,_maxPages:2,_focusedItem:null,_focusedIndex:-1,_offscreenFocusedItem:null,_focusBackfillItem:null,_itemsPerRow:1,_itemWidth:0,_rowHeight:0,_templateCost:0,get _physicalBottom(){return this._physicalTop+this._physicalSize},get _scrollBottom(){return this._scrollPosition+this._viewportHeight},get _virtualEnd(){return this._virtualStart+this._physicalCount-1},get _hiddenContentSize(){var size=this.grid?this._physicalRows*this._rowHeight:this._physicalSize;return size-this._viewportHeight},get _maxScrollTop(){return this._estScrollHeight-this._viewportHeight+this._scrollerPaddingTop},_minVirtualStart:0,get _maxVirtualStart(){return Math.max(0,this._virtualCount-this._physicalCount)},_virtualStartVal:0,set _virtualStart(val){this._virtualStartVal=Math.min(this._maxVirtualStart,Math.max(this._minVirtualStart,val))},get _virtualStart(){return this._virtualStartVal||0},_physicalStartVal:0,set _physicalStart(val){this._physicalStartVal=val%this._physicalCount;if(this._physicalStartVal<0){this._physicalStartVal=this._physicalCount+this._physicalStartVal}this._physicalEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _physicalStart(){return this._physicalStartVal||0},_physicalCountVal:0,set _physicalCount(val){this._physicalCountVal=val;this._physicalEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _physicalCount(){return this._physicalCountVal},_physicalEnd:0,get _optPhysicalSize(){if(this.grid){return this._estRowsInView*this._rowHeight*this._maxPages}return this._viewportHeight*this._maxPages},get _isVisible(){return Boolean(this.offsetWidth||this.offsetHeight)},get firstVisibleIndex(){if(this._firstVisibleIndexVal===null){var physicalOffset=Math.floor(this._physicalTop+this._scrollerPaddingTop);this._firstVisibleIndexVal=this._iterateItems(function(pidx,vidx){physicalOffset+=this._getPhysicalSizeIncrement(pidx);if(physicalOffset>this._scrollPosition){return this.grid?vidx-vidx%this._itemsPerRow:vidx}if(this.grid&&this._virtualCount-1===vidx){return vidx-vidx%this._itemsPerRow}})||0}return this._firstVisibleIndexVal},get lastVisibleIndex(){if(this._lastVisibleIndexVal===null){if(this.grid){var lastIndex=this.firstVisibleIndex+this._estRowsInView*this._itemsPerRow-1;this._lastVisibleIndexVal=Math.min(this._virtualCount,lastIndex)}else{var physicalOffset=this._physicalTop;this._iterateItems(function(pidx,vidx){if(physicalOffset<this._scrollBottom){this._lastVisibleIndexVal=vidx}else{return true}physicalOffset+=this._getPhysicalSizeIncrement(pidx)})}}return this._lastVisibleIndexVal},get _defaultScrollTarget(){return this},get _virtualRowCount(){return Math.ceil(this._virtualCount/this._itemsPerRow)},get _estRowsInView(){return Math.ceil(this._viewportHeight/this._rowHeight)},get _physicalRows(){return Math.ceil(this._physicalCount/this._itemsPerRow)},ready:function(){this.addEventListener("focus",this._didFocus.bind(this),true)},attached:function(){if(this._physicalCount===0){this._debounceTemplate(this._render)}this.listen(this,"iron-resize","_resizeHandler")},detached:function(){this.unlisten(this,"iron-resize","_resizeHandler")},_setOverflow:function(scrollTarget){this.style.webkitOverflowScrolling=scrollTarget===this?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},updateViewportBoundaries:function(){this._scrollerPaddingTop=this.scrollTarget===this?0:parseInt(window.getComputedStyle(this)["padding-top"],10);this._viewportWidth=this.$.items.offsetWidth;this._viewportHeight=this._scrollTargetHeight;this.grid&&this._updateGridMetrics()},_scrollHandler:function(){var scrollTop=Math.max(0,Math.min(this._maxScrollTop,this._scrollTop));var delta=scrollTop-this._scrollPosition;var isScrollingDown=delta>=0;this._scrollPosition=scrollTop;this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;if(Math.abs(delta)>this._physicalSize){var idxAdjustment=Math.round(delta/this._physicalAverage)*this._itemsPerRow;this._physicalTop=this._physicalTop+delta;this._virtualStart=this._virtualStart+idxAdjustment;this._physicalStart=this._physicalStart+idxAdjustment;this._update()}else{var reusables=this._getReusables(isScrollingDown);if(isScrollingDown){this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.indexes.length}else{this._virtualStart=this._virtualStart-reusables.indexes.length;this._physicalStart=this._physicalStart-reusables.indexes.length}if(reusables.indexes.length===0){this._increasePoolIfNeeded()}else{this._update(reusables.indexes,isScrollingDown?null:reusables.indexes)}}},_getReusables:function(fromTop){var ith,lastIth,offsetContent,physicalItemHeight;var idxs=[];var protectedOffsetContent=this._hiddenContentSize*this._ratio;var virtualStart=this._virtualStart;var virtualEnd=this._virtualEnd;var physicalCount=this._physicalCount;var physicalTop=this._physicalTop+this._scrollerPaddingTop;var scrollTop=this._scrollTop;var scrollBottom=this._scrollBottom;if(fromTop){ith=this._physicalStart;lastIth=this._physicalEnd;offsetContent=scrollTop-physicalTop}else{ith=this._physicalEnd;lastIth=this._physicalStart;offsetContent=this._physicalBottom-scrollBottom}while(true){physicalItemHeight=this._getPhysicalSizeIncrement(ith);offsetContent=offsetContent-physicalItemHeight;if(idxs.length>=physicalCount||offsetContent<=protectedOffsetContent){break}if(fromTop){if(virtualEnd+idxs.length+1>=this._virtualCount){break}if(physicalTop+physicalItemHeight>=scrollTop){break}idxs.push(ith);physicalTop=physicalTop+physicalItemHeight;ith=(ith+1)%physicalCount}else{if(virtualStart-idxs.length<=0){break}if(physicalTop+this._physicalSize-physicalItemHeight<=scrollBottom){break}idxs.push(ith);physicalTop=physicalTop-physicalItemHeight;ith=ith===0?physicalCount-1:ith-1}}return{indexes:idxs,physicalTop:physicalTop-this._scrollerPaddingTop}},_update:function(itemSet,movingUp){if(itemSet&&itemSet.length===0){return}this._manageFocus();this._assignModels(itemSet);this._updateMetrics(itemSet);if(movingUp){while(movingUp.length){var idx=movingUp.pop();this._physicalTop-=this._getPhysicalSizeIncrement(idx)}}this._positionItems();this._updateScrollerSize();this._increasePoolIfNeeded()},_createPool:function(size){var physicalItems=new Array(size);this._ensureTemplatized();for(var i=0;i<size;i++){var inst=this.stamp(null);physicalItems[i]=inst.root.querySelector("*");Polymer.dom(this).appendChild(inst.root)}return physicalItems},_increasePoolIfNeeded:function(){if(this._viewportHeight===0){return false}var self=this;var isClientFull=this._physicalBottom>=this._scrollBottom&&this._physicalTop<=this._scrollPosition;if(this._physicalSize>=this._optPhysicalSize&&isClientFull){return false}var maxPoolSize=Math.round(this._physicalCount*.5);if(!isClientFull){this._debounceTemplate(this._increasePool.bind(this,maxPoolSize));return true}this._yield(function(){self._increasePool(Math.min(maxPoolSize,Math.max(1,Math.round(50/self._templateCost))))});return true},_yield:function(cb){var g=window;var handle=g.requestIdleCallback?g.requestIdleCallback(cb):g.setTimeout(cb,16);Polymer.dom.addDebouncer({complete:function(){g.cancelIdleCallback?g.cancelIdleCallback(handle):g.clearTimeout(handle);cb()}})},_increasePool:function(missingItems){var nextPhysicalCount=Math.min(this._physicalCount+missingItems,this._virtualCount-this._virtualStart,Math.max(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevPhysicalCount=this._physicalCount;var delta=nextPhysicalCount-prevPhysicalCount;var ts=window.performance.now();if(delta<=0){return}[].push.apply(this._physicalItems,this._createPool(delta));[].push.apply(this._physicalSizes,new Array(delta));this._physicalCount=prevPhysicalCount+delta;if(this._physicalStart>this._physicalEnd&&this._isIndexRendered(this._focusedIndex)&&this._getPhysicalIndex(this._focusedIndex)<this._physicalEnd){this._physicalStart=this._physicalStart+delta}this._update();this._templateCost=(window.performance.now()-ts)/delta},_render:function(){if(this.isAttached&&this._isVisible){if(this._physicalCount===0){this.updateViewportBoundaries();this._increasePool(DEFAULT_PHYSICAL_COUNT)}else{var reusables=this._getReusables(true);this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.indexes.length;this._update(reusables.indexes);this._update()}}},_ensureTemplatized:function(){if(!this.ctor){var props={};props.__key__=true;props[this.as]=true;props[this.indexAs]=true;props[this.selectedAs]=true;props.tabIndex=true;this._instanceProps=props;this._userTemplate=Polymer.dom(this).querySelector("template");if(this._userTemplate){this.templatize(this._userTemplate)}else{console.warn("iron-list requires a template to be provided in light-dom")}}},_getStampedChildren:function(){return this._physicalItems},_forwardInstancePath:function(inst,path,value){if(path.indexOf(this.as+".")===0){this.notifyPath("items."+inst.__key__+"."+path.slice(this.as.length+1),value)}},_forwardParentProp:function(prop,value){if(this._physicalItems){this._physicalItems.forEach(function(item){item._templateInstance[prop]=value},this)}},_forwardParentPath:function(path,value){if(this._physicalItems){this._physicalItems.forEach(function(item){item._templateInstance.notifyPath(path,value,true)},this)}},_forwardItemPath:function(path,value){if(!this._physicalIndexForKey){return}var dot=path.indexOf(".");var key=path.substring(0,dot<0?path.length:dot);var idx=this._physicalIndexForKey[key];var offscreenItem=this._offscreenFocusedItem;var el=offscreenItem&&offscreenItem._templateInstance.__key__===key?offscreenItem:this._physicalItems[idx];if(!el||el._templateInstance.__key__!==key){return}if(dot>=0){path=this.as+"."+path.substring(dot+1);el._templateInstance.notifyPath(path,value,true)}else{var currentItem=el._templateInstance[this.as];if(Array.isArray(this.selectedItems)){for(var i=0;i<this.selectedItems.length;i++){if(this.selectedItems[i]===currentItem){this.set("selectedItems."+i,value);break}}}else if(this.selectedItem===currentItem){this.set("selectedItem",value)}el._templateInstance[this.as]=value}},_itemsChanged:function(change){if(change.path==="items"){this._virtualStart=0;this._physicalTop=0;this._virtualCount=this.items?this.items.length:0;this._collection=this.items?Polymer.Collection.get(this.items):null;this._physicalIndexForKey={};this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;this._physicalCount=this._physicalCount||0;this._physicalItems=this._physicalItems||[];this._physicalSizes=this._physicalSizes||[];this._physicalStart=0;this._resetScrollPosition(0);this._removeFocusedItem();this._debounceTemplate(this._render)}else if(change.path==="items.splices"){this._adjustVirtualIndex(change.value.indexSplices);this._virtualCount=this.items?this.items.length:0;this._debounceTemplate(this._render)}else{this._forwardItemPath(change.path.split(".").slice(1).join("."),change.value)}},_adjustVirtualIndex:function(splices){splices.forEach(function(splice){splice.removed.forEach(this._removeItem,this);if(splice.index<this._virtualStart){var delta=Math.max(splice.addedCount-splice.removed.length,splice.index-this._virtualStart);this._virtualStart=this._virtualStart+delta;if(this._focusedIndex>=0){this._focusedIndex=this._focusedIndex+delta}}},this)},_removeItem:function(item){this.$.selector.deselect(item);if(this._focusedItem&&this._focusedItem._templateInstance[this.as]===item){this._removeFocusedItem()}},_iterateItems:function(fn,itemSet){var pidx,vidx,rtn,i;if(arguments.length===2&&itemSet){for(i=0;i<itemSet.length;i++){pidx=itemSet[i];vidx=this._computeVidx(pidx);if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}else{pidx=this._physicalStart;vidx=this._virtualStart;for(;pidx<this._physicalCount;pidx++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}for(pidx=0;pidx<this._physicalStart;pidx++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}},_computeVidx:function(pidx){if(pidx>=this._physicalStart){return this._virtualStart+(pidx-this._physicalStart)}return this._virtualStart+(this._physicalCount-this._physicalStart)+pidx},_assignModels:function(itemSet){this._iterateItems(function(pidx,vidx){var el=this._physicalItems[pidx];var inst=el._templateInstance;var item=this.items&&this.items[vidx];if(item!=null){inst[this.as]=item;inst.__key__=this._collection.getKey(item);inst[this.selectedAs]=this.$.selector.isSelected(item);inst[this.indexAs]=vidx;inst.tabIndex=this._focusedIndex===vidx?0:-1;this._physicalIndexForKey[inst.__key__]=pidx;el.removeAttribute("hidden")}else{inst.__key__=null;el.setAttribute("hidden","")}},itemSet)},_updateMetrics:function(itemSet){Polymer.dom.flush();var newPhysicalSize=0;var oldPhysicalSize=0;var prevAvgCount=this._physicalAverageCount;var prevPhysicalAvg=this._physicalAverage;this._iterateItems(function(pidx,vidx){oldPhysicalSize+=this._physicalSizes[pidx]||0;this._physicalSizes[pidx]=this._physicalItems[pidx].offsetHeight;newPhysicalSize+=this._physicalSizes[pidx];this._physicalAverageCount+=this._physicalSizes[pidx]?1:0},itemSet);if(this.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this._physicalCount/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this._physicalSize+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==prevAvgCount){this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPhysicalSize)/this._physicalAverageCount)}},_updateGridMetrics:function(){this._itemWidth=this._physicalCount>0?this._physicalItems[0].getBoundingClientRect().width:200;this._rowHeight=this._physicalCount>0?this._physicalItems[0].offsetHeight:200;this._itemsPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._itemWidth):this._itemsPerRow},_positionItems:function(){this._adjustScrollPosition();var y=this._physicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this._itemWidth;var rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateItems(function(pidx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modulus*this._itemWidth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalItems[pidx]);if(this._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._iterateItems(function(pidx,vidx){this.translate3d(0,y+"px",0,this._physicalItems[pidx]);y+=this._physicalSizes[pidx]})}},_getPhysicalSizeIncrement:function(pidx){if(!this.grid){return this._physicalSizes[pidx]}if(this._computeVidx(pidx)%this._itemsPerRow!==this._itemsPerRow-1){return 0}return this._rowHeight},_shouldRenderNextRow:function(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},_adjustScrollPosition:function(){var deltaHeight=this._virtualStart===0?this._physicalTop:Math.min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){this._physicalTop=this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._physicalTop!==0){this._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScrollPosition:function(pos){if(this.scrollTarget){this._scrollTop=pos;this._scrollPosition=this._scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.grid){this._estScrollHeight=this._virtualRowCount*this._rowHeight}else{this._estScrollHeight=this._physicalBottom+Math.max(this._virtualCount-this._physicalCount-this._virtualStart,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scrollHeight===0;forceUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-this._physicalSize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height<this._estScrollHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scrollHeight)>=this._optPhysicalSize){this.$.items.style.height=this._estScrollHeight+"px";this._scrollHeight=this._estScrollHeight}},scrollToItem:function(item){return this.scrollToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){if(typeof idx!=="number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flush();if(this._physicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtualCount-1);if(!this._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virtualStart=this.grid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assignModels();this._updateMetrics();this._physicalTop=Math.floor(this._virtualStart/this._itemsPerRow)*this._physicalAverage;var currentTopItem=this._physicalStart;var currentVirtualItem=this._virtualStart;var targetOffsetTop=0;var hiddenContentSize=this._hiddenContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hiddenContentSize){targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(currentTopItem);currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirtualItem++}this._updateScrollerSize(true);this._positionItems();this._resetScrollPosition(this._physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._increasePoolIfNeeded();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null},_resetAverage:function(){this._physicalAverage=0;this._physicalAverageCount=0},_resizeHandler:function(){var delta=Math.abs(this._viewportHeight-this._scrollTargetHeight);if(IOS&&delta>0&&delta<100){return}Polymer.dom.addDebouncer(this.debounce("_debounceTemplate",function(){this.updateViewportBoundaries();this._render();if(this._isVisible){this.toggleScrollListener(true);if(this._physicalCount>0){this._resetAverage();this.scrollToIndex(this.firstVisibleIndex)}}else{this.toggleScrollListener(false)}}.bind(this),1))},_getModelFromItem:function(item){var key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx!=null){return this._physicalItems[pidx]._templateInstance}return null},_getNormalizedItem:function(item){if(this._collection.getKey(item)===undefined){if(typeof item==="number"){item=this.items[item];if(!item){throw new RangeError("<item> not found")}return item}throw new TypeError("<item> should be a valid item")}return item},selectItem:function(item){item=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(!this.multiSelection&&this.selectedItem){this.deselectItem(this.selectedItem)}if(model){model[this.selectedAs]=true}this.$.selector.select(item);this.updateSizeForItem(item)},deselectItem:function(item){item=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(model){model[this.selectedAs]=false}this.$.selector.deselect(item);this.updateSizeForItem(item)},toggleSelectionForItem:function(item){item=this._getNormalizedItem(item);if(this.$.selector.isSelected(item)){this.deselectItem(item)}else{this.selectItem(item)}},clearSelection:function(){function unselect(item){var model=this._getModelFromItem(item);if(model){model[this.selectedAs]=false}}if(Array.isArray(this.selectedItems)){this.selectedItems.forEach(unselect,this)}else if(this.selectedItem){unselect.call(this,this.selectedItem)}this.$.selector.clearSelection()},_selectionEnabledChanged:function(selectionEnabled){var handler=selectionEnabled?this.listen:this.unlisten;handler.call(this,this,"tap","_selectionHandler")},_selectionHandler:function(e){var model=this.modelForElement(e.target);if(!model){return}var modelTabIndex,activeElTabIndex;var target=Polymer.dom(e).path[0];var activeEl=Polymer.dom(this.domHost?this.domHost.root:document).activeElement;var physicalItem=this._physicalItems[this._getPhysicalIndex(model[this.indexAs])];if(target.localName==="input"||target.localName==="button"||target.localName==="select"){return}modelTabIndex=model.tabIndex;model.tabIndex=SECRET_TABINDEX;activeElTabIndex=activeEl?activeEl.tabIndex:-1;model.tabIndex=modelTabIndex;if(activeEl&&physicalItem!==activeEl&&physicalItem.contains(activeEl)&&activeElTabIndex!==SECRET_TABINDEX){return}this.toggleSelectionForItem(model[this.as])},_multiSelectionChanged:function(multiSelection){this.clearSelection();this.$.selector.multi=multiSelection},updateSizeForItem:function(item){item=this._getNormalizedItem(item);var key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx!=null){this._updateMetrics([pidx]);this._positionItems()}},_manageFocus:function(){var fidx=this._focusedIndex;if(fidx>=0&&fidx<this._virtualCount){if(this._isIndexRendered(fidx)){this._restoreFocusedItem()}else{this._createFocusBackfillItem()}}else if(this._virtualCount>0&&this._physicalCount>0){this._focusedIndex=this._virtualStart;this._focusedItem=this._physicalItems[this._physicalStart]}},_isIndexRendered:function(idx){return idx>=this._virtualStart&&idx<=this._virtualEnd},_isIndexVisible:function(idx){return idx>=this.firstVisibleIndex&&idx<=this.lastVisibleIndex},_getPhysicalIndex:function(idx){return this._physicalIndexForKey[this._collection.getKey(this._getNormalizedItem(idx))]},_focusPhysicalItem:function(idx){if(idx<0||idx>=this._virtualCount){return}this._restoreFocusedItem();if(!this._isIndexRendered(idx)){this.scrollToIndex(idx)}var physicalItem=this._physicalItems[this._getPhysicalIndex(idx)];var model=physicalItem._templateInstance;var focusable;model.tabIndex=SECRET_TABINDEX;if(physicalItem.tabIndex===SECRET_TABINDEX){focusable=physicalItem}if(!focusable){focusable=Polymer.dom(physicalItem).querySelector('[tabindex="'+SECRET_TABINDEX+'"]')}model.tabIndex=0;this._focusedIndex=idx;focusable&&focusable.focus()},_removeFocusedItem:function(){if(this._offscreenFocusedItem){Polymer.dom(this).removeChild(this._offscreenFocusedItem)}this._offscreenFocusedItem=null;this._focusBackfillItem=null;this._focusedItem=null;this._focusedIndex=-1},_createFocusBackfillItem:function(){var fidx=this._focusedIndex;var pidx=this._getPhysicalIndex(fidx);if(this._offscreenFocusedItem||pidx==null||fidx<0){return}if(!this._focusBackfillItem){var stampedTemplate=this.stamp(null);this._focusBackfillItem=stampedTemplate.root.querySelector("*");Polymer.dom(this).appendChild(stampedTemplate.root)}this._offscreenFocusedItem=this._physicalItems[pidx];this._offscreenFocusedItem._templateInstance.tabIndex=0;this._physicalItems[pidx]=this._focusBackfillItem;this.translate3d(0,HIDDEN_Y,0,this._offscreenFocusedItem)},_restoreFocusedItem:function(){var pidx,fidx=this._focusedIndex;if(!this._offscreenFocusedItem||this._focusedIndex<0){return}this._assignModels();pidx=this._getPhysicalIndex(fidx);if(pidx!=null){this._focusBackfillItem=this._physicalItems[pidx];this._focusBackfillItem._templateInstance.tabIndex=-1;this._physicalItems[pidx]=this._offscreenFocusedItem;this._offscreenFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfillItem)}},_didFocus:function(e){var targetModel=this.modelForElement(e.target);var focusedModel=this._focusedItem?this._focusedItem._templateInstance:null;var hasOffscreenFocusedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedIndex;if(!targetModel||!focusedModel){return}if(focusedModel===targetModel){if(!this._isIndexVisible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem();focusedModel.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs];this._focusedIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysicalIndex(fidx)];if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._update()}}},_didMoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_didMoveDown:function(e){e.detail.keyboardEvent.preventDefault();this._focusPhysicalItem(this._focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this._focusedIndex);this._selectionHandler(e.detail.keyboardEvent)}})})();Polymer({is:"iron-scroll-threshold",properties:{upperThreshold:{type:Number,value:100},lowerThreshold:{type:Number,value:100},upperTriggered:{type:Boolean,value:false,notify:true,readOnly:true},lowerTriggered:{type:Boolean,value:false,notify:true,readOnly:true},horizontal:{type:Boolean,value:false}},behaviors:[Polymer.IronScrollTargetBehavior],observers:["_setOverflow(scrollTarget)","_initCheck(horizontal, isAttached)"],get _defaultScrollTarget(){return this},_setOverflow:function(scrollTarget){this.style.overflow=scrollTarget===this?"auto":""},_scrollHandler:function(){var THROTTLE_THRESHOLD=200;if(!this.isDebouncerActive("_checkTheshold")){this.debounce("_checkTheshold",function(){this.checkScrollThesholds()},THROTTLE_THRESHOLD)}},_initCheck:function(horizontal,isAttached){if(isAttached){this.debounce("_init",function(){this.clearTriggers();this.checkScrollThesholds()})}},checkScrollThesholds:function(){if(!this.scrollTarget||this.lowerTriggered&&this.upperTriggered){return}var upperScrollValue=this.horizontal?this._scrollLeft:this._scrollTop;var lowerScrollValue=this.horizontal?this.scrollTarget.scrollWidth-this._scrollTargetWidth-this._scrollLeft:this.scrollTarget.scrollHeight-this._scrollTargetHeight-this._scrollTop;if(upperScrollValue<=this.upperThreshold&&!this.upperTriggered){this._setUpperTriggered(true);this.fire("upper-threshold")}if(lowerScrollValue<=this.lowerThreshold&&!this.lowerTriggered){this._setLowerTriggered(true);this.fire("lower-threshold")}},clearTriggers:function(){this._setUpperTriggered(false);this._setLowerTriggered(false)}}); +Polymer({is:"history-toolbar",properties:{count:{type:Number,value:0,observer:"changeToolbarView_"},itemsSelected_:{type:Boolean,value:false,reflectToAttribute:true},searchTerm:{type:String,observer:"searchTermChanged_",notify:true},spinnerActive:{type:Boolean,value:false},hasDrawer:{type:Boolean,reflectToAttribute:true},isGroupedMode:{type:Boolean,reflectToAttribute:true},groupedRange:{type:Number,reflectToAttribute:true,notify:true},groupedOffset:{type:Number,notify:true},hasMoreResults:Boolean,querying:Boolean,queryInfo:Object,showMenuPromo:Boolean,showSyncNotice:Boolean},get searchField(){return this.$["main-toolbar"].getSearchField()},showSearchField:function(){this.searchField.showAndFocus()},changeToolbarView_:function(){this.itemsSelected_=this.count>0},searchTermChanged_:function(){if(this.searchField.getValue()!=this.searchTerm){this.searchField.showAndFocus();this.searchField.setValue(this.searchTerm)}},onSearchChanged_:function(event){this.searchTerm=event.detail},onInfoButtonTap_:function(){var dropdown=this.$.syncNotice.get();dropdown.positionTarget=this.$$("#info-button-icon");if(dropdown.style.display=="none")dropdown.open()},onClearSelectionTap_:function(){this.fire("unselect-all")},onDeleteTap_:function(){this.fire("delete-selected")},deletingAllowed_:function(){return loadTimeData.getBoolean("allowDeletingHistory")},numberOfItemsSelected_:function(count){return count>0?loadTimeData.getStringF("itemsSelected",count):""},getHistoryInterval_:function(){var info=this.queryInfo;if(this.groupedRange==HistoryRange.WEEK)return info.queryInterval;if(this.groupedRange==HistoryRange.MONTH)return info.queryStartMonth},onTodayTap_:function(){if(!this.querying)this.groupedOffset=0},onPrevTap_:function(){if(!this.querying)this.groupedOffset=this.groupedOffset+1},onNextTap_:function(){if(!this.querying)this.groupedOffset=this.groupedOffset-1},isToday_:function(){return this.groupedOffset==0}});(function(){"use strict";Polymer.IronA11yAnnouncer=Polymer({is:"iron-a11y-announcer",properties:{mode:{type:String,value:"polite"},_text:{type:String,value:""}},created:function(){if(!Polymer.IronA11yAnnouncer.instance){Polymer.IronA11yAnnouncer.instance=this}document.body.addEventListener("iron-announce",this._onIronAnnounce.bind(this))},announce:function(text){this._text="";this.async(function(){this._text=text},100)},_onIronAnnounce:function(event){if(event.detail&&event.detail.text){this.announce(event.detail.text)}}});Polymer.IronA11yAnnouncer.instance=null;Polymer.IronA11yAnnouncer.requestAvailability=function(){if(!Polymer.IronA11yAnnouncer.instance){Polymer.IronA11yAnnouncer.instance=document.createElement("iron-a11y-announcer")}document.body.appendChild(Polymer.IronA11yAnnouncer.instance)}})();(function(){var IOS=navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/);var IOS_TOUCH_SCROLLING=IOS&&IOS[1]>=8;var DEFAULT_PHYSICAL_COUNT=3;var HIDDEN_Y="-10000px";var ITEM_WIDTH=0;var ITEM_HEIGHT=1;var SECRET_TABINDEX=-100;Polymer({is:"iron-list",properties:{items:{type:Array},maxPhysicalCount:{type:Number,value:500},as:{type:String,value:"item"},indexAs:{type:String,value:"index"},selectedAs:{type:String,value:"selected"},grid:{type:Boolean,value:false,reflectToAttribute:true},selectionEnabled:{type:Boolean,value:false},selectedItem:{type:Object,notify:true},selectedItems:{type:Object,notify:true},multiSelection:{type:Boolean,value:false}},observers:["_itemsChanged(items.*)","_selectionEnabledChanged(selectionEnabled)","_multiSelectionChanged(multiSelection)","_setOverflow(scrollTarget)"],behaviors:[Polymer.Templatizer,Polymer.IronResizableBehavior,Polymer.IronA11yKeysBehavior,Polymer.IronScrollTargetBehavior],keyBindings:{up:"_didMoveUp",down:"_didMoveDown",enter:"_didEnter"},_ratio:.5,_scrollerPaddingTop:0,_scrollPosition:0,_physicalSize:0,_physicalAverage:0,_physicalAverageCount:0,_physicalTop:0,_virtualCount:0,_physicalIndexForKey:null,_estScrollHeight:0,_scrollHeight:0,_viewportHeight:0,_viewportWidth:0,_physicalItems:null,_physicalSizes:null,_firstVisibleIndexVal:null,_lastVisibleIndexVal:null,_collection:null,_maxPages:2,_focusedItem:null,_focusedIndex:-1,_offscreenFocusedItem:null,_focusBackfillItem:null,_itemsPerRow:1,_itemWidth:0,_rowHeight:0,_templateCost:0,get _physicalBottom(){return this._physicalTop+this._physicalSize},get _scrollBottom(){return this._scrollPosition+this._viewportHeight},get _virtualEnd(){return this._virtualStart+this._physicalCount-1},get _hiddenContentSize(){var size=this.grid?this._physicalRows*this._rowHeight:this._physicalSize;return size-this._viewportHeight},get _maxScrollTop(){return this._estScrollHeight-this._viewportHeight+this._scrollerPaddingTop},_minVirtualStart:0,get _maxVirtualStart(){return Math.max(0,this._virtualCount-this._physicalCount)},_virtualStartVal:0,set _virtualStart(val){this._virtualStartVal=Math.min(this._maxVirtualStart,Math.max(this._minVirtualStart,val))},get _virtualStart(){return this._virtualStartVal||0},_physicalStartVal:0,set _physicalStart(val){this._physicalStartVal=val%this._physicalCount;if(this._physicalStartVal<0){this._physicalStartVal=this._physicalCount+this._physicalStartVal}this._physicalEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _physicalStart(){return this._physicalStartVal||0},_physicalCountVal:0,set _physicalCount(val){this._physicalCountVal=val;this._physicalEnd=(this._physicalStart+this._physicalCount-1)%this._physicalCount},get _physicalCount(){return this._physicalCountVal},_physicalEnd:0,get _optPhysicalSize(){if(this.grid){return this._estRowsInView*this._rowHeight*this._maxPages}return this._viewportHeight*this._maxPages},get _isVisible(){return Boolean(this.offsetWidth||this.offsetHeight)},get firstVisibleIndex(){if(this._firstVisibleIndexVal===null){var physicalOffset=Math.floor(this._physicalTop+this._scrollerPaddingTop);this._firstVisibleIndexVal=this._iterateItems(function(pidx,vidx){physicalOffset+=this._getPhysicalSizeIncrement(pidx);if(physicalOffset>this._scrollPosition){return this.grid?vidx-vidx%this._itemsPerRow:vidx}if(this.grid&&this._virtualCount-1===vidx){return vidx-vidx%this._itemsPerRow}})||0}return this._firstVisibleIndexVal},get lastVisibleIndex(){if(this._lastVisibleIndexVal===null){if(this.grid){var lastIndex=this.firstVisibleIndex+this._estRowsInView*this._itemsPerRow-1;this._lastVisibleIndexVal=Math.min(this._virtualCount,lastIndex)}else{var physicalOffset=this._physicalTop;this._iterateItems(function(pidx,vidx){if(physicalOffset<this._scrollBottom){this._lastVisibleIndexVal=vidx}else{return true}physicalOffset+=this._getPhysicalSizeIncrement(pidx)})}}return this._lastVisibleIndexVal},get _defaultScrollTarget(){return this},get _virtualRowCount(){return Math.ceil(this._virtualCount/this._itemsPerRow)},get _estRowsInView(){return Math.ceil(this._viewportHeight/this._rowHeight)},get _physicalRows(){return Math.ceil(this._physicalCount/this._itemsPerRow)},ready:function(){this.addEventListener("focus",this._didFocus.bind(this),true)},attached:function(){if(this._physicalCount===0){this._debounceTemplate(this._render)}this.listen(this,"iron-resize","_resizeHandler")},detached:function(){this.unlisten(this,"iron-resize","_resizeHandler")},_setOverflow:function(scrollTarget){this.style.webkitOverflowScrolling=scrollTarget===this?"touch":"";this.style.overflow=scrollTarget===this?"auto":""},updateViewportBoundaries:function(){this._scrollerPaddingTop=this.scrollTarget===this?0:parseInt(window.getComputedStyle(this)["padding-top"],10);this._viewportWidth=this.$.items.offsetWidth;this._viewportHeight=this._scrollTargetHeight;this.grid&&this._updateGridMetrics()},_scrollHandler:function(){var scrollTop=Math.max(0,Math.min(this._maxScrollTop,this._scrollTop));var delta=scrollTop-this._scrollPosition;var isScrollingDown=delta>=0;this._scrollPosition=scrollTop;this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;if(Math.abs(delta)>this._physicalSize){var idxAdjustment=Math.round(delta/this._physicalAverage)*this._itemsPerRow;this._physicalTop=this._physicalTop+delta;this._virtualStart=this._virtualStart+idxAdjustment;this._physicalStart=this._physicalStart+idxAdjustment;this._update()}else{var reusables=this._getReusables(isScrollingDown);if(isScrollingDown){this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.indexes.length}else{this._virtualStart=this._virtualStart-reusables.indexes.length;this._physicalStart=this._physicalStart-reusables.indexes.length}if(reusables.indexes.length===0){this._increasePoolIfNeeded()}else{this._update(reusables.indexes,isScrollingDown?null:reusables.indexes)}}},_getReusables:function(fromTop){var ith,lastIth,offsetContent,physicalItemHeight;var idxs=[];var protectedOffsetContent=this._hiddenContentSize*this._ratio;var virtualStart=this._virtualStart;var virtualEnd=this._virtualEnd;var physicalCount=this._physicalCount;var physicalTop=this._physicalTop+this._scrollerPaddingTop;var scrollTop=this._scrollTop;var scrollBottom=this._scrollBottom;if(fromTop){ith=this._physicalStart;lastIth=this._physicalEnd;offsetContent=scrollTop-physicalTop}else{ith=this._physicalEnd;lastIth=this._physicalStart;offsetContent=this._physicalBottom-scrollBottom}while(true){physicalItemHeight=this._getPhysicalSizeIncrement(ith);offsetContent=offsetContent-physicalItemHeight;if(idxs.length>=physicalCount||offsetContent<=protectedOffsetContent){break}if(fromTop){if(virtualEnd+idxs.length+1>=this._virtualCount){break}if(physicalTop+physicalItemHeight>=scrollTop){break}idxs.push(ith);physicalTop=physicalTop+physicalItemHeight;ith=(ith+1)%physicalCount}else{if(virtualStart-idxs.length<=0){break}if(physicalTop+this._physicalSize-physicalItemHeight<=scrollBottom){break}idxs.push(ith);physicalTop=physicalTop-physicalItemHeight;ith=ith===0?physicalCount-1:ith-1}}return{indexes:idxs,physicalTop:physicalTop-this._scrollerPaddingTop}},_update:function(itemSet,movingUp){if(itemSet&&itemSet.length===0){return}this._manageFocus();this._assignModels(itemSet);this._updateMetrics(itemSet);if(movingUp){while(movingUp.length){var idx=movingUp.pop();this._physicalTop-=this._getPhysicalSizeIncrement(idx)}}this._positionItems();this._updateScrollerSize();this._increasePoolIfNeeded()},_createPool:function(size){var physicalItems=new Array(size);this._ensureTemplatized();for(var i=0;i<size;i++){var inst=this.stamp(null);physicalItems[i]=inst.root.querySelector("*");Polymer.dom(this).appendChild(inst.root)}return physicalItems},_increasePoolIfNeeded:function(){if(this._viewportHeight===0){return false}var self=this;var isClientFull=this._physicalBottom>=this._scrollBottom&&this._physicalTop<=this._scrollPosition;if(this._physicalSize>=this._optPhysicalSize&&isClientFull){return false}var maxPoolSize=Math.round(this._physicalCount*.5);if(!isClientFull){this._debounceTemplate(this._increasePool.bind(this,maxPoolSize));return true}this._yield(function(){self._increasePool(Math.min(maxPoolSize,Math.max(1,Math.round(50/self._templateCost))))});return true},_yield:function(cb){var g=window;var handle=g.requestIdleCallback?g.requestIdleCallback(cb):g.setTimeout(cb,16);Polymer.dom.addDebouncer({complete:function(){g.cancelIdleCallback?g.cancelIdleCallback(handle):g.clearTimeout(handle);cb()}})},_increasePool:function(missingItems){var nextPhysicalCount=Math.min(this._physicalCount+missingItems,this._virtualCount-this._virtualStart,Math.max(this.maxPhysicalCount,DEFAULT_PHYSICAL_COUNT));var prevPhysicalCount=this._physicalCount;var delta=nextPhysicalCount-prevPhysicalCount;var ts=window.performance.now();if(delta<=0){return}[].push.apply(this._physicalItems,this._createPool(delta));[].push.apply(this._physicalSizes,new Array(delta));this._physicalCount=prevPhysicalCount+delta;if(this._physicalStart>this._physicalEnd&&this._isIndexRendered(this._focusedIndex)&&this._getPhysicalIndex(this._focusedIndex)<this._physicalEnd){this._physicalStart=this._physicalStart+delta}this._update();this._templateCost=(window.performance.now()-ts)/delta},_render:function(){if(this.isAttached&&this._isVisible){if(this._physicalCount===0){this.updateViewportBoundaries();this._increasePool(DEFAULT_PHYSICAL_COUNT)}else{var reusables=this._getReusables(true);this._physicalTop=reusables.physicalTop;this._virtualStart=this._virtualStart+reusables.indexes.length;this._physicalStart=this._physicalStart+reusables.indexes.length;this._update(reusables.indexes);this._update()}}},_ensureTemplatized:function(){if(!this.ctor){var props={};props.__key__=true;props[this.as]=true;props[this.indexAs]=true;props[this.selectedAs]=true;props.tabIndex=true;this._instanceProps=props;this._userTemplate=Polymer.dom(this).querySelector("template");if(this._userTemplate){this.templatize(this._userTemplate)}else{console.warn("iron-list requires a template to be provided in light-dom")}}},_getStampedChildren:function(){return this._physicalItems},_forwardInstancePath:function(inst,path,value){if(path.indexOf(this.as+".")===0){this.notifyPath("items."+inst.__key__+"."+path.slice(this.as.length+1),value)}},_forwardParentProp:function(prop,value){if(this._physicalItems){this._physicalItems.forEach(function(item){item._templateInstance[prop]=value},this)}},_forwardParentPath:function(path,value){if(this._physicalItems){this._physicalItems.forEach(function(item){item._templateInstance.notifyPath(path,value,true)},this)}},_forwardItemPath:function(path,value){if(!this._physicalIndexForKey){return}var dot=path.indexOf(".");var key=path.substring(0,dot<0?path.length:dot);var idx=this._physicalIndexForKey[key];var offscreenItem=this._offscreenFocusedItem;var el=offscreenItem&&offscreenItem._templateInstance.__key__===key?offscreenItem:this._physicalItems[idx];if(!el||el._templateInstance.__key__!==key){return}if(dot>=0){path=this.as+"."+path.substring(dot+1);el._templateInstance.notifyPath(path,value,true)}else{var currentItem=el._templateInstance[this.as];if(Array.isArray(this.selectedItems)){for(var i=0;i<this.selectedItems.length;i++){if(this.selectedItems[i]===currentItem){this.set("selectedItems."+i,value);break}}}else if(this.selectedItem===currentItem){this.set("selectedItem",value)}el._templateInstance[this.as]=value}},_itemsChanged:function(change){if(change.path==="items"){this._virtualStart=0;this._physicalTop=0;this._virtualCount=this.items?this.items.length:0;this._collection=this.items?Polymer.Collection.get(this.items):null;this._physicalIndexForKey={};this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null;this._physicalCount=this._physicalCount||0;this._physicalItems=this._physicalItems||[];this._physicalSizes=this._physicalSizes||[];this._physicalStart=0;this._resetScrollPosition(0);this._removeFocusedItem();this._debounceTemplate(this._render)}else if(change.path==="items.splices"){this._adjustVirtualIndex(change.value.indexSplices);this._virtualCount=this.items?this.items.length:0;this._debounceTemplate(this._render)}else{this._forwardItemPath(change.path.split(".").slice(1).join("."),change.value)}},_adjustVirtualIndex:function(splices){splices.forEach(function(splice){splice.removed.forEach(this._removeItem,this);if(splice.index<this._virtualStart){var delta=Math.max(splice.addedCount-splice.removed.length,splice.index-this._virtualStart);this._virtualStart=this._virtualStart+delta;if(this._focusedIndex>=0){this._focusedIndex=this._focusedIndex+delta}}},this)},_removeItem:function(item){this.$.selector.deselect(item);if(this._focusedItem&&this._focusedItem._templateInstance[this.as]===item){this._removeFocusedItem()}},_iterateItems:function(fn,itemSet){var pidx,vidx,rtn,i;if(arguments.length===2&&itemSet){for(i=0;i<itemSet.length;i++){pidx=itemSet[i];vidx=this._computeVidx(pidx);if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}else{pidx=this._physicalStart;vidx=this._virtualStart;for(;pidx<this._physicalCount;pidx++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}for(pidx=0;pidx<this._physicalStart;pidx++,vidx++){if((rtn=fn.call(this,pidx,vidx))!=null){return rtn}}}},_computeVidx:function(pidx){if(pidx>=this._physicalStart){return this._virtualStart+(pidx-this._physicalStart)}return this._virtualStart+(this._physicalCount-this._physicalStart)+pidx},_assignModels:function(itemSet){this._iterateItems(function(pidx,vidx){var el=this._physicalItems[pidx];var inst=el._templateInstance;var item=this.items&&this.items[vidx];if(item!=null){inst[this.as]=item;inst.__key__=this._collection.getKey(item);inst[this.selectedAs]=this.$.selector.isSelected(item);inst[this.indexAs]=vidx;inst.tabIndex=this._focusedIndex===vidx?0:-1;this._physicalIndexForKey[inst.__key__]=pidx;el.removeAttribute("hidden")}else{inst.__key__=null;el.setAttribute("hidden","")}},itemSet)},_updateMetrics:function(itemSet){Polymer.dom.flush();var newPhysicalSize=0;var oldPhysicalSize=0;var prevAvgCount=this._physicalAverageCount;var prevPhysicalAvg=this._physicalAverage;this._iterateItems(function(pidx,vidx){oldPhysicalSize+=this._physicalSizes[pidx]||0;this._physicalSizes[pidx]=this._physicalItems[pidx].offsetHeight;newPhysicalSize+=this._physicalSizes[pidx];this._physicalAverageCount+=this._physicalSizes[pidx]?1:0},itemSet);if(this.grid){this._updateGridMetrics();this._physicalSize=Math.ceil(this._physicalCount/this._itemsPerRow)*this._rowHeight}else{this._physicalSize=this._physicalSize+newPhysicalSize-oldPhysicalSize}if(this._physicalAverageCount!==prevAvgCount){this._physicalAverage=Math.round((prevPhysicalAvg*prevAvgCount+newPhysicalSize)/this._physicalAverageCount)}},_updateGridMetrics:function(){this._itemWidth=this._physicalCount>0?this._physicalItems[0].getBoundingClientRect().width:200;this._rowHeight=this._physicalCount>0?this._physicalItems[0].offsetHeight:200;this._itemsPerRow=this._itemWidth?Math.floor(this._viewportWidth/this._itemWidth):this._itemsPerRow},_positionItems:function(){this._adjustScrollPosition();var y=this._physicalTop;if(this.grid){var totalItemWidth=this._itemsPerRow*this._itemWidth;var rowOffset=(this._viewportWidth-totalItemWidth)/2;this._iterateItems(function(pidx,vidx){var modulus=vidx%this._itemsPerRow;var x=Math.floor(modulus*this._itemWidth+rowOffset);this.translate3d(x+"px",y+"px",0,this._physicalItems[pidx]);if(this._shouldRenderNextRow(vidx)){y+=this._rowHeight}})}else{this._iterateItems(function(pidx,vidx){this.translate3d(0,y+"px",0,this._physicalItems[pidx]);y+=this._physicalSizes[pidx]})}},_getPhysicalSizeIncrement:function(pidx){if(!this.grid){return this._physicalSizes[pidx]}if(this._computeVidx(pidx)%this._itemsPerRow!==this._itemsPerRow-1){return 0}return this._rowHeight},_shouldRenderNextRow:function(vidx){return vidx%this._itemsPerRow===this._itemsPerRow-1},_adjustScrollPosition:function(){var deltaHeight=this._virtualStart===0?this._physicalTop:Math.min(this._scrollPosition+this._physicalTop,0);if(deltaHeight){this._physicalTop=this._physicalTop-deltaHeight;if(!IOS_TOUCH_SCROLLING&&this._physicalTop!==0){this._resetScrollPosition(this._scrollTop-deltaHeight)}}},_resetScrollPosition:function(pos){if(this.scrollTarget){this._scrollTop=pos;this._scrollPosition=this._scrollTop}},_updateScrollerSize:function(forceUpdate){if(this.grid){this._estScrollHeight=this._virtualRowCount*this._rowHeight}else{this._estScrollHeight=this._physicalBottom+Math.max(this._virtualCount-this._physicalCount-this._virtualStart,0)*this._physicalAverage}forceUpdate=forceUpdate||this._scrollHeight===0;forceUpdate=forceUpdate||this._scrollPosition>=this._estScrollHeight-this._physicalSize;forceUpdate=forceUpdate||this.grid&&this.$.items.style.height<this._estScrollHeight;if(forceUpdate||Math.abs(this._estScrollHeight-this._scrollHeight)>=this._optPhysicalSize){this.$.items.style.height=this._estScrollHeight+"px";this._scrollHeight=this._estScrollHeight}},scrollToItem:function(item){return this.scrollToIndex(this.items.indexOf(item))},scrollToIndex:function(idx){if(typeof idx!=="number"||idx<0||idx>this.items.length-1){return}Polymer.dom.flush();if(this._physicalCount===0){return}idx=Math.min(Math.max(idx,0),this._virtualCount-1);if(!this._isIndexRendered(idx)||idx>=this._maxVirtualStart){this._virtualStart=this.grid?idx-this._itemsPerRow*2:idx-1}this._manageFocus();this._assignModels();this._updateMetrics();this._physicalTop=Math.floor(this._virtualStart/this._itemsPerRow)*this._physicalAverage;var currentTopItem=this._physicalStart;var currentVirtualItem=this._virtualStart;var targetOffsetTop=0;var hiddenContentSize=this._hiddenContentSize;while(currentVirtualItem<idx&&targetOffsetTop<=hiddenContentSize){targetOffsetTop=targetOffsetTop+this._getPhysicalSizeIncrement(currentTopItem);currentTopItem=(currentTopItem+1)%this._physicalCount;currentVirtualItem++}this._updateScrollerSize(true);this._positionItems();this._resetScrollPosition(this._physicalTop+this._scrollerPaddingTop+targetOffsetTop);this._increasePoolIfNeeded();this._firstVisibleIndexVal=null;this._lastVisibleIndexVal=null},_resetAverage:function(){this._physicalAverage=0;this._physicalAverageCount=0},_resizeHandler:function(){var delta=Math.abs(this._viewportHeight-this._scrollTargetHeight);if(IOS&&delta>0&&delta<100){return}Polymer.dom.addDebouncer(this.debounce("_debounceTemplate",function(){this.updateViewportBoundaries();this._render();if(this._isVisible){this.toggleScrollListener(true);if(this._physicalCount>0){this._resetAverage();this.scrollToIndex(this.firstVisibleIndex)}}else{this.toggleScrollListener(false)}}.bind(this),1))},_getModelFromItem:function(item){var key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx!=null){return this._physicalItems[pidx]._templateInstance}return null},_getNormalizedItem:function(item){if(this._collection.getKey(item)===undefined){if(typeof item==="number"){item=this.items[item];if(!item){throw new RangeError("<item> not found")}return item}throw new TypeError("<item> should be a valid item")}return item},selectItem:function(item){item=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(!this.multiSelection&&this.selectedItem){this.deselectItem(this.selectedItem)}if(model){model[this.selectedAs]=true}this.$.selector.select(item);this.updateSizeForItem(item)},deselectItem:function(item){item=this._getNormalizedItem(item);var model=this._getModelFromItem(item);if(model){model[this.selectedAs]=false}this.$.selector.deselect(item);this.updateSizeForItem(item)},toggleSelectionForItem:function(item){item=this._getNormalizedItem(item);if(this.$.selector.isSelected(item)){this.deselectItem(item)}else{this.selectItem(item)}},clearSelection:function(){function unselect(item){var model=this._getModelFromItem(item);if(model){model[this.selectedAs]=false}}if(Array.isArray(this.selectedItems)){this.selectedItems.forEach(unselect,this)}else if(this.selectedItem){unselect.call(this,this.selectedItem)}this.$.selector.clearSelection()},_selectionEnabledChanged:function(selectionEnabled){var handler=selectionEnabled?this.listen:this.unlisten;handler.call(this,this,"tap","_selectionHandler")},_selectionHandler:function(e){var model=this.modelForElement(e.target);if(!model){return}var modelTabIndex,activeElTabIndex;var target=Polymer.dom(e).path[0];var activeEl=Polymer.dom(this.domHost?this.domHost.root:document).activeElement;var physicalItem=this._physicalItems[this._getPhysicalIndex(model[this.indexAs])];if(target.localName==="input"||target.localName==="button"||target.localName==="select"){return}modelTabIndex=model.tabIndex;model.tabIndex=SECRET_TABINDEX;activeElTabIndex=activeEl?activeEl.tabIndex:-1;model.tabIndex=modelTabIndex;if(activeEl&&physicalItem!==activeEl&&physicalItem.contains(activeEl)&&activeElTabIndex!==SECRET_TABINDEX){return}this.toggleSelectionForItem(model[this.as])},_multiSelectionChanged:function(multiSelection){this.clearSelection();this.$.selector.multi=multiSelection},updateSizeForItem:function(item){item=this._getNormalizedItem(item);var key=this._collection.getKey(item);var pidx=this._physicalIndexForKey[key];if(pidx!=null){this._updateMetrics([pidx]);this._positionItems()}},_manageFocus:function(){var fidx=this._focusedIndex;if(fidx>=0&&fidx<this._virtualCount){if(this._isIndexRendered(fidx)){this._restoreFocusedItem()}else{this._createFocusBackfillItem()}}else if(this._virtualCount>0&&this._physicalCount>0){this._focusedIndex=this._virtualStart;this._focusedItem=this._physicalItems[this._physicalStart]}},_isIndexRendered:function(idx){return idx>=this._virtualStart&&idx<=this._virtualEnd},_isIndexVisible:function(idx){return idx>=this.firstVisibleIndex&&idx<=this.lastVisibleIndex},_getPhysicalIndex:function(idx){return this._physicalIndexForKey[this._collection.getKey(this._getNormalizedItem(idx))]},_focusPhysicalItem:function(idx){if(idx<0||idx>=this._virtualCount){return}this._restoreFocusedItem();if(!this._isIndexRendered(idx)){this.scrollToIndex(idx)}var physicalItem=this._physicalItems[this._getPhysicalIndex(idx)];var model=physicalItem._templateInstance;var focusable;model.tabIndex=SECRET_TABINDEX;if(physicalItem.tabIndex===SECRET_TABINDEX){focusable=physicalItem}if(!focusable){focusable=Polymer.dom(physicalItem).querySelector('[tabindex="'+SECRET_TABINDEX+'"]')}model.tabIndex=0;this._focusedIndex=idx;focusable&&focusable.focus()},_removeFocusedItem:function(){if(this._offscreenFocusedItem){Polymer.dom(this).removeChild(this._offscreenFocusedItem)}this._offscreenFocusedItem=null;this._focusBackfillItem=null;this._focusedItem=null;this._focusedIndex=-1},_createFocusBackfillItem:function(){var fidx=this._focusedIndex;var pidx=this._getPhysicalIndex(fidx);if(this._offscreenFocusedItem||pidx==null||fidx<0){return}if(!this._focusBackfillItem){var stampedTemplate=this.stamp(null);this._focusBackfillItem=stampedTemplate.root.querySelector("*");Polymer.dom(this).appendChild(stampedTemplate.root)}this._offscreenFocusedItem=this._physicalItems[pidx];this._offscreenFocusedItem._templateInstance.tabIndex=0;this._physicalItems[pidx]=this._focusBackfillItem;this.translate3d(0,HIDDEN_Y,0,this._offscreenFocusedItem)},_restoreFocusedItem:function(){var pidx,fidx=this._focusedIndex;if(!this._offscreenFocusedItem||this._focusedIndex<0){return}this._assignModels();pidx=this._getPhysicalIndex(fidx);if(pidx!=null){this._focusBackfillItem=this._physicalItems[pidx];this._focusBackfillItem._templateInstance.tabIndex=-1;this._physicalItems[pidx]=this._offscreenFocusedItem;this._offscreenFocusedItem=null;this.translate3d(0,HIDDEN_Y,0,this._focusBackfillItem)}},_didFocus:function(e){var targetModel=this.modelForElement(e.target);var focusedModel=this._focusedItem?this._focusedItem._templateInstance:null;var hasOffscreenFocusedItem=this._offscreenFocusedItem!==null;var fidx=this._focusedIndex;if(!targetModel||!focusedModel){return}if(focusedModel===targetModel){if(!this._isIndexVisible(fidx)){this.scrollToIndex(fidx)}}else{this._restoreFocusedItem();focusedModel.tabIndex=-1;targetModel.tabIndex=0;fidx=targetModel[this.indexAs];this._focusedIndex=fidx;this._focusedItem=this._physicalItems[this._getPhysicalIndex(fidx)];if(hasOffscreenFocusedItem&&!this._offscreenFocusedItem){this._update()}}},_didMoveUp:function(){this._focusPhysicalItem(this._focusedIndex-1)},_didMoveDown:function(e){e.detail.keyboardEvent.preventDefault();this._focusPhysicalItem(this._focusedIndex+1)},_didEnter:function(e){this._focusPhysicalItem(this._focusedIndex);this._selectionHandler(e.detail.keyboardEvent)}})})();Polymer({is:"iron-scroll-threshold",properties:{upperThreshold:{type:Number,value:100},lowerThreshold:{type:Number,value:100},upperTriggered:{type:Boolean,value:false,notify:true,readOnly:true},lowerTriggered:{type:Boolean,value:false,notify:true,readOnly:true},horizontal:{type:Boolean,value:false}},behaviors:[Polymer.IronScrollTargetBehavior],observers:["_setOverflow(scrollTarget)","_initCheck(horizontal, isAttached)"],get _defaultScrollTarget(){return this},_setOverflow:function(scrollTarget){this.style.overflow=scrollTarget===this?"auto":""},_scrollHandler:function(){var THROTTLE_THRESHOLD=200;if(!this.isDebouncerActive("_checkTheshold")){this.debounce("_checkTheshold",function(){this.checkScrollThesholds()},THROTTLE_THRESHOLD)}},_initCheck:function(horizontal,isAttached){if(isAttached){this.debounce("_init",function(){this.clearTriggers();this.checkScrollThesholds()})}},checkScrollThesholds:function(){if(!this.scrollTarget||this.lowerTriggered&&this.upperTriggered){return}var upperScrollValue=this.horizontal?this._scrollLeft:this._scrollTop;var lowerScrollValue=this.horizontal?this.scrollTarget.scrollWidth-this._scrollTargetWidth-this._scrollLeft:this.scrollTarget.scrollHeight-this._scrollTargetHeight-this._scrollTop;if(upperScrollValue<=this.upperThreshold&&!this.upperTriggered){this._setUpperTriggered(true);this.fire("upper-threshold")}if(lowerScrollValue<=this.lowerThreshold&&!this.lowerTriggered){this._setLowerTriggered(true);this.fire("lower-threshold")}},clearTriggers:function(){this._setUpperTriggered(false);this._setLowerTriggered(false)}}); // Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
diff --git a/chrome/browser/resources/md_history/app.html b/chrome/browser/resources/md_history/app.html index a25db6e..389c807e 100644 --- a/chrome/browser/resources/md_history/app.html +++ b/chrome/browser/resources/md_history/app.html
@@ -77,10 +77,9 @@ grouped-offset="{{queryState_.groupedOffset}}" grouped-range="{{queryState_.range}}" has-drawer="[[hasDrawer_]]" - is-grouped-mode="{{grouped_}}" - query-end-time="[[queryResult_.info.queryEndTime]]" has-more-results="[[!queryResult_.info.finished]]" - query-start-time="[[queryResult_.info.queryStartTime]]" + is-grouped-mode="{{grouped_}}" + query-info="[[queryResult_.info]]" querying="[[queryState_.querying]]" search-term="{{queryState_.searchTerm}}" show-menu-promo="[[showMenuPromo_]]"
diff --git a/chrome/browser/resources/md_history/app.vulcanized.html b/chrome/browser/resources/md_history/app.vulcanized.html index 2b72563..6e59cfd3c 100644 --- a/chrome/browser/resources/md_history/app.vulcanized.html +++ b/chrome/browser/resources/md_history/app.vulcanized.html
@@ -2465,7 +2465,7 @@ </paper-tabs> <div id="grouped-nav-container"> <span id="grouped-date"> - {{getHistoryInterval_(queryStartTime, queryEndTime)}} + [[getHistoryInterval_(queryInfo)]] </span> <button is="paper-icon-button-light" id="today-button" class="icon-button" title="$i18n{rangeToday}" on-tap="onTodayTap_" disabled="[[isToday_(groupedOffset)]]"> <iron-icon icon="history:today"></iron-icon> @@ -3324,7 +3324,7 @@ <history-list id="infinite-list" querying="[[queryState.querying]]" searched-term="[[queryResult.info.term]]"> </history-list> <template is="dom-if" if="[[grouped]]"> - <history-grouped-list id="grouped-list" range="[[groupedRange]]" query-start-time="[[queryResult.info.queryStartTime]]" query-end-time="[[queryResult.info.queryEndTime]]" searched-term="[[queryResult.info.term]]"> + <history-grouped-list id="grouped-list" range="[[groupedRange]]" query-interval="[[queryResult.info.queryInterval]]" searched-term="[[queryResult.info.term]]"> </history-grouped-list> </template> </iron-pages> @@ -3753,7 +3753,7 @@ </style> <history-router selected-page="{{selectedPage_}}" query-state="{{queryState_}}"> </history-router> - <history-toolbar id="toolbar" grouped-offset="{{queryState_.groupedOffset}}" grouped-range="{{queryState_.range}}" has-drawer="[[hasDrawer_]]" is-grouped-mode="{{grouped_}}" query-end-time="[[queryResult_.info.queryEndTime]]" has-more-results="[[!queryResult_.info.finished]]" query-start-time="[[queryResult_.info.queryStartTime]]" querying="[[queryState_.querying]]" search-term="{{queryState_.searchTerm}}" show-menu-promo="[[showMenuPromo_]]" show-sync-notice="[[showSyncNotice_(hasSyncedResults, selectedPage_)]]" spinner-active="[[shouldShowSpinner_(queryState_.querying, + <history-toolbar id="toolbar" grouped-offset="{{queryState_.groupedOffset}}" grouped-range="{{queryState_.range}}" has-drawer="[[hasDrawer_]]" has-more-results="[[!queryResult_.info.finished]]" is-grouped-mode="{{grouped_}}" query-info="[[queryResult_.info]]" querying="[[queryState_.querying]]" search-term="{{queryState_.searchTerm}}" show-menu-promo="[[showMenuPromo_]]" show-sync-notice="[[showSyncNotice_(hasSyncedResults, selectedPage_)]]" spinner-active="[[shouldShowSpinner_(queryState_.querying, queryState_.incremental, queryState_.searchTerm)]]"> </history-toolbar>
diff --git a/chrome/browser/resources/md_history/compiled_resources2.gyp b/chrome/browser/resources/md_history/compiled_resources2.gyp index c9bf9f1..d358c68 100644 --- a/chrome/browser/resources/md_history/compiled_resources2.gyp +++ b/chrome/browser/resources/md_history/compiled_resources2.gyp
@@ -77,6 +77,8 @@ '<(DEPTH)/ui/webui/resources/cr_elements/cr_toolbar/compiled_resources2.gyp:cr_toolbar', '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:load_time_data', '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:util', + 'constants', + '../history/compiled_resources2.gyp:externs', ], 'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'], },
diff --git a/chrome/browser/resources/md_history/grouped_list.js b/chrome/browser/resources/md_history/grouped_list.js index a867d17..f1664bf8 100644 --- a/chrome/browser/resources/md_history/grouped_list.js +++ b/chrome/browser/resources/md_history/grouped_list.js
@@ -35,9 +35,7 @@ // An array of history entries in reverse chronological order. historyData: Array, - queryStartTime: String, - - queryEndTime: String, + queryInterval: String, range: Number, }, @@ -125,7 +123,7 @@ } else if (this.range == HistoryRange.MONTH) { // Group each all visits into a single list. this.groupedHistoryData_ = [{ - title: this.queryStartTime + ' – ' + this.queryEndTime, + title: this.queryInterval, domains: this.createHistoryDomains_(this.historyData) }]; }
diff --git a/chrome/browser/resources/md_history/history_toolbar.html b/chrome/browser/resources/md_history/history_toolbar.html index b74503b..bdb42d3 100644 --- a/chrome/browser/resources/md_history/history_toolbar.html +++ b/chrome/browser/resources/md_history/history_toolbar.html
@@ -227,7 +227,7 @@ </paper-tabs> <div id="grouped-nav-container"> <span id="grouped-date"> - {{getHistoryInterval_(queryStartTime, queryEndTime)}} + [[getHistoryInterval_(queryInfo)]] </span> <button is="paper-icon-button-light" id="today-button"
diff --git a/chrome/browser/resources/md_history/history_toolbar.js b/chrome/browser/resources/md_history/history_toolbar.js index b7d8042..3700748 100644 --- a/chrome/browser/resources/md_history/history_toolbar.js +++ b/chrome/browser/resources/md_history/history_toolbar.js
@@ -60,15 +60,11 @@ notify: true, }, - querying: Boolean, - hasMoreResults: Boolean, - // The start time of the query range. - queryStartTime: String, + querying: Boolean, - // The end time of the query range. - queryEndTime: String, + queryInfo: Object, // Whether to show the menu promo (a tooltip that points at the menu button // in narrow mode). @@ -150,10 +146,13 @@ }, /** @private */ - getHistoryInterval_: function(queryStartTime, queryEndTime) { - // TODO(calamity): Fix the format of these dates. - return loadTimeData.getStringF( - 'historyInterval', queryStartTime, queryEndTime); + getHistoryInterval_: function() { + var info = this.queryInfo; + if (this.groupedRange == HistoryRange.WEEK) + return info.queryInterval; + + if (this.groupedRange == HistoryRange.MONTH) + return info.queryStartMonth; }, /** @private */
diff --git a/chrome/browser/resources/md_history/lazy_load.crisper.js b/chrome/browser/resources/md_history/lazy_load.crisper.js index 7df8a39..1f1f0a3 100644 --- a/chrome/browser/resources/md_history/lazy_load.crisper.js +++ b/chrome/browser/resources/md_history/lazy_load.crisper.js
@@ -2,7 +2,7 @@ // Copyright 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var HistoryDomain;var HistoryGroup;Polymer({is:"history-grouped-list",behaviors:[HistoryListBehavior],properties:{searchedTerm:{type:String,value:""},groupedHistoryData_:Array,historyData:Array,queryStartTime:String,queryEndTime:String,range:Number},observers:["updateGroupedHistoryData_(range, historyData)"],addNewResults:function(results,incremental,finished){this.historyData=results},createHistoryDomains_:function(visits){var domainIndexes={};var domains=[];for(var i=0,visit;visit=visits[i];i++){var domain=visit.domain;if(domainIndexes[domain]==undefined){domainIndexes[domain]=domains.length;domains.push({domain:domain,visits:[],expanded:false,rendered:false})}domains[domainIndexes[domain]].visits.push(visit)}var sortByVisits=function(a,b){return b.visits.length-a.visits.length};domains.sort(sortByVisits);return domains},updateGroupedHistoryData_:function(){if(this.historyData.length==0){this.groupedHistoryData_=[];return}if(this.range==HistoryRange.WEEK){var days=[];var currentDayVisits=[this.historyData[0]];var pushCurrentDay=function(){days.push({title:this.searchedTerm?currentDayVisits[0].dateShort:currentDayVisits[0].dateRelativeDay,domains:this.createHistoryDomains_(currentDayVisits)})}.bind(this);var visitsSameDay=function(a,b){if(this.searchedTerm)return a.dateShort==b.dateShort;return a.dateRelativeDay==b.dateRelativeDay}.bind(this);for(var i=1;i<this.historyData.length;i++){var visit=this.historyData[i];if(!visitsSameDay(visit,currentDayVisits[0])){pushCurrentDay();currentDayVisits=[]}currentDayVisits.push(visit)}pushCurrentDay();this.groupedHistoryData_=days}else if(this.range==HistoryRange.MONTH){this.groupedHistoryData_=[{title:this.queryStartTime+" – "+this.queryEndTime,domains:this.createHistoryDomains_(this.historyData)}]}},toggleDomainExpanded_:function(e){var collapse=e.currentTarget.parentNode.querySelector("iron-collapse");e.model.set("domain.rendered",true);setTimeout(function(){collapse.toggle()},0)},needsTimeGap_:function(groupIndex,domainIndex,itemIndex){var visits=this.groupedHistoryData_[groupIndex].domains[domainIndex].visits;return md_history.HistoryItem.needsTimeGap(visits,itemIndex,this.searchedTerm)},pathForItem_:function(groupIndex,domainIndex,itemIndex){return["groupedHistoryData_",groupIndex,"domains",domainIndex,"visits",itemIndex].join(".")},getWebsiteIconStyle_:function(domain){return"background-image: "+cr.icon.getFavicon(domain.visits[0].url)},getDropdownIcon_:function(expanded){return expanded?"cr:expand-less":"cr:expand-more"}}); +var HistoryDomain;var HistoryGroup;Polymer({is:"history-grouped-list",behaviors:[HistoryListBehavior],properties:{searchedTerm:{type:String,value:""},groupedHistoryData_:Array,historyData:Array,queryInterval:String,range:Number},observers:["updateGroupedHistoryData_(range, historyData)"],addNewResults:function(results,incremental,finished){this.historyData=results},createHistoryDomains_:function(visits){var domainIndexes={};var domains=[];for(var i=0,visit;visit=visits[i];i++){var domain=visit.domain;if(domainIndexes[domain]==undefined){domainIndexes[domain]=domains.length;domains.push({domain:domain,visits:[],expanded:false,rendered:false})}domains[domainIndexes[domain]].visits.push(visit)}var sortByVisits=function(a,b){return b.visits.length-a.visits.length};domains.sort(sortByVisits);return domains},updateGroupedHistoryData_:function(){if(this.historyData.length==0){this.groupedHistoryData_=[];return}if(this.range==HistoryRange.WEEK){var days=[];var currentDayVisits=[this.historyData[0]];var pushCurrentDay=function(){days.push({title:this.searchedTerm?currentDayVisits[0].dateShort:currentDayVisits[0].dateRelativeDay,domains:this.createHistoryDomains_(currentDayVisits)})}.bind(this);var visitsSameDay=function(a,b){if(this.searchedTerm)return a.dateShort==b.dateShort;return a.dateRelativeDay==b.dateRelativeDay}.bind(this);for(var i=1;i<this.historyData.length;i++){var visit=this.historyData[i];if(!visitsSameDay(visit,currentDayVisits[0])){pushCurrentDay();currentDayVisits=[]}currentDayVisits.push(visit)}pushCurrentDay();this.groupedHistoryData_=days}else if(this.range==HistoryRange.MONTH){this.groupedHistoryData_=[{title:this.queryInterval,domains:this.createHistoryDomains_(this.historyData)}]}},toggleDomainExpanded_:function(e){var collapse=e.currentTarget.parentNode.querySelector("iron-collapse");e.model.set("domain.rendered",true);setTimeout(function(){collapse.toggle()},0)},needsTimeGap_:function(groupIndex,domainIndex,itemIndex){var visits=this.groupedHistoryData_[groupIndex].domains[domainIndex].visits;return md_history.HistoryItem.needsTimeGap(visits,itemIndex,this.searchedTerm)},pathForItem_:function(groupIndex,domainIndex,itemIndex){return["groupedHistoryData_",groupIndex,"domains",domainIndex,"visits",itemIndex].join(".")},getWebsiteIconStyle_:function(domain){return"background-image: "+cr.icon.getFavicon(domain.visits[0].url)},getDropdownIcon_:function(expanded){return expanded?"cr:expand-less":"cr:expand-more"}}); // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file.
diff --git a/chrome/browser/resources/md_history/list_container.html b/chrome/browser/resources/md_history/list_container.html index 2c4971a..24410edf 100644 --- a/chrome/browser/resources/md_history/list_container.html +++ b/chrome/browser/resources/md_history/list_container.html
@@ -39,8 +39,7 @@ <template is="dom-if" if="[[grouped]]"> <history-grouped-list id="grouped-list" range="[[groupedRange]]" - query-start-time="[[queryResult.info.queryStartTime]]" - query-end-time="[[queryResult.info.queryEndTime]]" + query-interval="[[queryResult.info.queryInterval]]" searched-term="[[queryResult.info.term]]"> </history-grouped-list> </template>
diff --git a/chrome/browser/ssl/ssl_error_handler.cc b/chrome/browser/ssl/ssl_error_handler.cc index de91bcc..b0b4291 100644 --- a/chrome/browser/ssl/ssl_error_handler.cc +++ b/chrome/browser/ssl/ssl_error_handler.cc
@@ -25,6 +25,7 @@ #include "components/network_time/network_time_tracker.h" #include "components/ssl_errors/error_classification.h" #include "components/ssl_errors/error_info.h" +#include "content/public/browser/navigation_handle.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/render_frame_host.h" @@ -468,9 +469,11 @@ #endif } -void SSLErrorHandler::DidStartNavigationToPendingEntry( - const GURL& /* url */, - content::ReloadType /* reload_type */) { +void SSLErrorHandler::DidStartNavigation( + content::NavigationHandle* navigation_handle) { + if (!navigation_handle->IsInMainFrame() || navigation_handle->IsSamePage()) + return; + // Destroy the error handler on all new navigations. This ensures that the // handler is properly recreated when a hanging page is navigated to an SSL // error, even when the tab's WebContents doesn't change.
diff --git a/chrome/browser/ssl/ssl_error_handler.h b/chrome/browser/ssl/ssl_error_handler.h index 44213c1..c213c47 100644 --- a/chrome/browser/ssl/ssl_error_handler.h +++ b/chrome/browser/ssl/ssl_error_handler.h
@@ -126,9 +126,8 @@ const content::NotificationDetails& details) override; // content::WebContentsObserver: - void DidStartNavigationToPendingEntry( - const GURL& url, - content::ReloadType reload_type) override; + void DidStartNavigation( + content::NavigationHandle* navigation_handle) override; // content::WebContentsObserver: void NavigationStopped() override;
diff --git a/chrome/browser/ui/views/session_crashed_bubble_view.cc b/chrome/browser/ui/views/session_crashed_bubble_view.cc index f974ac00..0954fca 100644 --- a/chrome/browser/ui/views/session_crashed_bubble_view.cc +++ b/chrome/browser/ui/views/session_crashed_bubble_view.cc
@@ -33,6 +33,7 @@ #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/bubble/bubble_frame_view.h" @@ -200,7 +201,7 @@ web_contents_(web_contents), uma_option_(NULL), offer_uma_optin_(offer_uma_optin), - started_navigation_(false), + first_navigation_ignored_(false), restored_(false) { set_close_on_deactivate(false); registrar_.Add( @@ -334,17 +335,21 @@ RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP); } -void SessionCrashedBubbleView::DidStartNavigationToPendingEntry( - const GURL& url, - content::ReloadType reload_type) { - started_navigation_ = true; -} - void SessionCrashedBubbleView::DidFinishLoad( content::RenderFrameHost* render_frame_host, const GURL& validated_url) { - if (started_navigation_) - CloseBubble(); + // We want to close the bubble if the user navigates the first tab away after + // a crash. Ignore subframe navigations since they're noise and don't affect + // the desired behavior. + if (render_frame_host->GetParent()) + return; + + if (!first_navigation_ignored_) { + first_navigation_ignored_ = true; + return; + } + + CloseBubble(); } void SessionCrashedBubbleView::WasShown() {
diff --git a/chrome/browser/ui/views/session_crashed_bubble_view.h b/chrome/browser/ui/views/session_crashed_bubble_view.h index 93ad639..9779ce2 100644 --- a/chrome/browser/ui/views/session_crashed_bubble_view.h +++ b/chrome/browser/ui/views/session_crashed_bubble_view.h
@@ -75,9 +75,6 @@ int event_flags) override; // content::WebContentsObserver methods. - void DidStartNavigationToPendingEntry( - const GURL& url, - content::ReloadType reload_type) override; void DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) override; void WasShown() override; @@ -114,8 +111,9 @@ // Whether or not the UMA opt-in option should be shown. bool offer_uma_optin_; - // Whether or not a navigation has started on current tab. - bool started_navigation_; + // Whether or not the first navigation was ignored. This is needed because the + // bubble shouldn't go away when the new tab page loads after a crash. + bool first_navigation_ignored_; // Whether or not the user chose to restore previous session. It is used to // collect bubble usage stats.
diff --git a/chrome/browser/ui/webui/browsing_history_handler.cc b/chrome/browser/ui/webui/browsing_history_handler.cc index eb66d52..a951127 100644 --- a/chrome/browser/ui/webui/browsing_history_handler.cc +++ b/chrome/browser/ui/webui/browsing_history_handler.cc
@@ -14,7 +14,6 @@ #include "base/i18n/rtl.h" #include "base/i18n/time_formatting.h" #include "base/logging.h" -#include "base/memory/ptr_util.h" #include "base/strings/string16.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" @@ -523,6 +522,15 @@ "queryEndTime", GetRelativeDateLocalized(clock_.get(), query_results_info->end_time)); + results_info.SetString( + "queryStartMonth", + base::TimeFormatMonthAndYear(query_results_info->start_time)); + results_info.SetString( + "queryInterval", + base::DateIntervalFormat(query_results_info->start_time, + query_results_info->end_time, + base::DATE_FORMAT_MONTH_WEEKDAY_DAY)); + web_ui()->CallJavascriptFunctionUnsafe("historyResult", results_info, results_value); }
diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc index 5ff2be0..5ce93a4 100644 --- a/chrome/browser/ui/webui/history_ui.cc +++ b/chrome/browser/ui/webui/history_ui.cc
@@ -105,7 +105,6 @@ source->AddLocalizedString("searchButton", IDS_HISTORY_SEARCH_BUTTON); source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS); source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS); - source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL); source->AddLocalizedString("removeSelected", IDS_HISTORY_REMOVE_SELECTED_ITEMS); source->AddLocalizedString("clearAllHistory",
diff --git a/chrome/browser/ui/webui/md_history_ui.cc b/chrome/browser/ui/webui/md_history_ui.cc index 72069450..96c3b8ac 100644 --- a/chrome/browser/ui/webui/md_history_ui.cc +++ b/chrome/browser/ui/webui/md_history_ui.cc
@@ -80,7 +80,6 @@ IDS_MD_HISTORY_HAS_SYNCED_RESULTS); source->AddLocalizedString("hasSyncedResultsDescription", IDS_MD_HISTORY_HAS_SYNCED_RESULTS_DESCRIPTION); - source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL); source->AddLocalizedString("historyMenuButton", IDS_MD_HISTORY_HISTORY_MENU_DESCRIPTION); source->AddLocalizedString("historyMenuItem",
diff --git a/chrome/test/data/webui/history_browsertest.js b/chrome/test/data/webui/history_browsertest.js index 5633e5e..4118c98 100644 --- a/chrome/test/data/webui/history_browsertest.js +++ b/chrome/test/data/webui/history_browsertest.js
@@ -261,8 +261,7 @@ { term: searchText, finished: finished, - queryStartTime: queryStartTime, - queryEndTime: queryEndTime + queryInterval: queryStartTime + ' - ' + queryEndTime, }, results); }
diff --git a/chrome/test/data/webui/md_history/history_grouped_list_test.js b/chrome/test/data/webui/md_history/history_grouped_list_test.js index a586aa85..123aed9f 100644 --- a/chrome/test/data/webui/md_history/history_grouped_list_test.js +++ b/chrome/test/data/webui/md_history/history_grouped_list_test.js
@@ -78,8 +78,6 @@ test('items grouped by domain', function() { app.set('queryState_.range', HistoryRange.WEEK); var info = createHistoryInfo(); - info.queryStartTime = 'Yesterday'; - info.queryEndTime = 'Now'; app.historyResult(info, SIMPLE_RESULTS); return PolymerTest.flushTasks().then(function() { var data = groupedList.groupedHistoryData_; @@ -91,13 +89,27 @@ assertEquals(2, data[0].domains[0].visits.length); assertEquals(1, data[0].domains[1].visits.length); assertEquals(1, data[0].domains[2].visits.length); - - // Ensure the toolbar displays the correct begin and end time. - assertEquals('Yesterday', toolbar.queryStartTime); - assertEquals('Now', toolbar.queryEndTime); }); }); + test('toolbar dates appear in grouped mode', function() { + var getInfo = function() { + var info = createHistoryInfo(); + info.queryStartMonth = 'Dec 2016'; + info.queryInterval = 'Yesterday - Now'; + return info; + }; + app.set('queryState_.range', HistoryRange.MONTH); + app.historyResult(getInfo(), SIMPLE_RESULTS); + assertEquals( + 'Dec 2016', toolbar.$$('#grouped-date').textContent.trim()); + + app.set('queryState_.range', HistoryRange.WEEK); + app.historyResult(getInfo(), SIMPLE_RESULTS); + assertEquals( + 'Yesterday - Now', toolbar.$$('#grouped-date').textContent.trim()); + }); + test('items grouped by day in week view', function() { app.set('queryState_.range', HistoryRange.WEEK); app.historyResult(createHistoryInfo(), PER_DAY_RESULTS);
diff --git a/chrome/test/data/webui/md_history/test_util.js b/chrome/test/data/webui/md_history/test_util.js index 50624e4..b09085d 100644 --- a/chrome/test/data/webui/md_history/test_util.js +++ b/chrome/test/data/webui/md_history/test_util.js
@@ -90,8 +90,8 @@ return { finished: true, hasSyncedResults: false, - queryEndTime: 'Monday', - queryStartTime: 'Tuesday', + queryInterval: 'Monday - Tuesday', + queryMonth: 'June', term: searchTerm || '' }; }
diff --git a/components/history_strings.grdp b/components/history_strings.grdp index 9dca8554..46504804 100644 --- a/components/history_strings.grdp +++ b/components/history_strings.grdp
@@ -58,9 +58,6 @@ <message name="IDS_HISTORY_OTHER_FORMS_OF_HISTORY" desc="The notification at the top of the history page indicating that deleting Chrome browsing history will not delete other forms of history stored at Google My Activity."> Your Google Account may have other forms of browsing history at <ph name="BEGIN_LINK"><a target="_blank" href="$1"></ph>history.google.com<ph name="END_LINK"></a></ph> </message> - <message name="IDS_HISTORY_INTERVAL" desc="A history interval shown in the title. The dates are already localized strings."> - <ph name="START_DATE">$1<ex>Wednesday, Aug. 1, 2012</ex></ph> to <ph name="END_DATE">$2<ex>Thursday, Aug. 30, 2012</ex></ph> - </message> <message name="IDS_HISTORY_LOADING" desc="Text shown when we're loading the user's history"> Loading... </message>
diff --git a/components/signin/core/browser/gaia_cookie_manager_service.cc b/components/signin/core/browser/gaia_cookie_manager_service.cc index 3d14c26..0e1f935 100644 --- a/components/signin/core/browser/gaia_cookie_manager_service.cc +++ b/components/signin/core/browser/gaia_cookie_manager_service.cc
@@ -506,17 +506,20 @@ case net::CookieStore::ChangeCause::INSERTED: source += "INSERTED"; break; - case net::CookieStore::ChangeCause::EXPLICIT_DELETE: - source += "EXPLICIT_DELETE"; + case net::CookieStore::ChangeCause::EXPLICIT: + source += "EXPLICIT"; break; - case net::CookieStore::ChangeCause::EXPLICIT_DUPLICATE_IN_BACKING_STORE: - source += "EXPLICIT_DUPLICATE_IN_BACKING_STORE"; + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN: + source += "EXPLICIT_DELETE_BETWEEN"; break; - case net::CookieStore::ChangeCause::EXPLICIT_DONT_RECORD: - source += "EXPLICIT_DONT_RECORD"; + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE: + source += "EXPLICIT_DELETE_PREDICATE"; break; - case net::CookieStore::ChangeCause::EXPLICIT_LAST_ENTRY: - source += "EXPLICIT_LAST_ENTRY"; + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE: + source += "EXPLICIT_DELETE_SINGLE"; + break; + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL: + source += "EXPLICIT_DELETE_CANONICAL"; break; case net::CookieStore::ChangeCause::UNKNOWN_DELETION: source += "UNKNOWN_DELETION";
diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc index d2d04be..c19559b 100644 --- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc +++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
@@ -186,13 +186,16 @@ agent_host_->DispatchProtocolMessage(this, json_command); // Some messages are dispatched synchronously. // Only run loop if we are not finished yet. - if (in_dispatch_ && wait) { - waiting_for_command_result_id_ = last_sent_id_; - base::RunLoop().Run(); - } + if (in_dispatch_ && wait) + WaitForResponse(); in_dispatch_ = false; } + void WaitForResponse() { + waiting_for_command_result_id_ = last_sent_id_; + base::RunLoop().Run(); + } + bool HasValue(const std::string& path) { base::Value* value = 0; return result_->Get(path, &value); @@ -409,14 +412,26 @@ int modifier, int windowsKeyCode, int nativeKeyCode, - const std::string& key) { + const std::string& key, + bool wait) { std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); params->SetString("type", type); params->SetInteger("modifiers", modifier); params->SetInteger("windowsVirtualKeyCode", windowsKeyCode); params->SetInteger("nativeVirtualKeyCode", nativeKeyCode); params->SetString("key", key); - SendCommand("Input.dispatchKeyEvent", std::move(params)); + SendCommand("Input.dispatchKeyEvent", std::move(params), wait); + } +}; + +class SyntheticMouseEventTest : public DevToolsProtocolTest { + protected: + void SendMouseEvent(const std::string& type, int x, int y, bool wait) { + std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); + params->SetString("type", type); + params->SetInteger("x", x); + params->SetInteger("y", y); + SendCommand("Input.dispatchMouseEvent", std::move(params), wait); } }; @@ -435,8 +450,8 @@ DOMMessageQueue dom_message_queue; // Send enter (keycode 13). - SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter"); - SendKeyEvent("keyUp", 0, 13, 13, "Enter"); + SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter", true); + SendKeyEvent("keyUp", 0, 13, 13, "Enter", true); std::string key; ASSERT_TRUE(dom_message_queue.WaitForMessage(&key)); @@ -445,8 +460,8 @@ EXPECT_EQ("\"Enter\"", key); // Send escape (keycode 27). - SendKeyEvent("rawKeyDown", 0, 27, 27, "Escape"); - SendKeyEvent("keyUp", 0, 27, 27, "Escape"); + SendKeyEvent("rawKeyDown", 0, 27, 27, "Escape", true); + SendKeyEvent("keyUp", 0, 27, 27, "Escape", true); ASSERT_TRUE(dom_message_queue.WaitForMessage(&key)); EXPECT_EQ("\"Escape\"", key); @@ -454,6 +469,59 @@ EXPECT_EQ("\"Escape\"", key); } +IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyboardEventAck) { + NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); + Attach(); + ASSERT_TRUE(content::ExecuteScript( + shell()->web_contents()->GetRenderViewHost(), + "document.body.addEventListener('keydown', () => console.log('x'));")); + + scoped_refptr<InputMsgWatcher> filter = new InputMsgWatcher( + RenderWidgetHostImpl::From( + shell()->web_contents()->GetRenderViewHost()->GetWidget()), + blink::WebInputEvent::MouseMove); + + SendCommand("Runtime.enable", nullptr); + SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter", false); + + // We expect that the console log message event arrives *before* the input + // event ack, and the subsequent command response for Input.dispatchKeyEvent. + WaitForNotification("Runtime.consoleAPICalled"); + EXPECT_THAT(console_messages_, ElementsAre("x")); + EXPECT_FALSE(filter->HasReceivedAck()); + EXPECT_EQ(1u, result_ids_.size()); + + WaitForResponse(); + EXPECT_EQ(2u, result_ids_.size()); +} + +IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, MouseEventAck) { + NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); + Attach(); + ASSERT_TRUE(content::ExecuteScript( + shell()->web_contents()->GetRenderViewHost(), + "document.body.addEventListener('mousemove', () => console.log('x'));")); + + scoped_refptr<InputMsgWatcher> filter = new InputMsgWatcher( + RenderWidgetHostImpl::From( + shell()->web_contents()->GetRenderViewHost()->GetWidget()), + blink::WebInputEvent::MouseMove); + + SendCommand("Runtime.enable", nullptr); + SendMouseEvent("mouseMoved", 15, 15, false); + + // We expect that the console log message event arrives *before* the input + // event ack, and the subsequent command response for + // Input.dispatchMouseEvent. + WaitForNotification("Runtime.consoleAPICalled"); + EXPECT_THAT(console_messages_, ElementsAre("x")); + EXPECT_FALSE(filter->HasReceivedAck()); + EXPECT_EQ(1u, result_ids_.size()); + + WaitForResponse(); + EXPECT_EQ(2u, result_ids_.size()); +} + namespace { bool DecodePNG(std::string base64_data, SkBitmap* bitmap) { std::string png_data;
diff --git a/content/browser/devtools/protocol/input_handler.cc b/content/browser/devtools/protocol/input_handler.cc index fd29a38..072456c 100644 --- a/content/browser/devtools/protocol/input_handler.cc +++ b/content/browser/devtools/protocol/input_handler.cc
@@ -192,6 +192,7 @@ InputHandler::InputHandler() : DevToolsDomainHandler(Input::Metainfo::domainName), host_(nullptr), + input_queued_(false), page_scale_factor_(1.0), last_id_(0), weak_factory_(this) { @@ -207,7 +208,28 @@ } void InputHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { + ClearPendingKeyAndMouseCallbacks(); + if (host_) + host_->GetRenderWidgetHost()->RemoveInputEventObserver(this); host_ = host; + if (host) + host->GetRenderWidgetHost()->AddInputEventObserver(this); +} + +void InputHandler::OnInputEvent(const blink::WebInputEvent& event) { + input_queued_ = true; +} + +void InputHandler::OnInputEventAck(const blink::WebInputEvent& event) { + if (blink::WebInputEvent::isKeyboardEventType(event.type()) && + !pending_key_callbacks_.empty()) { + pending_key_callbacks_.front()->sendSuccess(); + pending_key_callbacks_.pop_front(); + } else if (blink::WebInputEvent::isMouseEventType(event.type()) && + !pending_mouse_callbacks_.empty()) { + pending_mouse_callbacks_.front()->sendSuccess(); + pending_mouse_callbacks_.pop_front(); + } } void InputHandler::Wire(UberDispatcher* dispatcher) { @@ -221,10 +243,13 @@ } Response InputHandler::Disable() { + ClearPendingKeyAndMouseCallbacks(); + if (host_) + host_->GetRenderWidgetHost()->RemoveInputEventObserver(this); return Response::OK(); } -Response InputHandler::DispatchKeyEvent( +void InputHandler::DispatchKeyEvent( const std::string& type, Maybe<int> modifiers, Maybe<double> timestamp, @@ -237,7 +262,8 @@ Maybe<int> native_virtual_key_code, Maybe<bool> auto_repeat, Maybe<bool> is_keypad, - Maybe<bool> is_system_key) { + Maybe<bool> is_system_key, + std::unique_ptr<DispatchKeyEventCallback> callback) { blink::WebInputEvent::Type web_event_type; if (type == Input::DispatchKeyEvent::TypeEnum::KeyDown) { @@ -249,8 +275,9 @@ } else if (type == Input::DispatchKeyEvent::TypeEnum::RawKeyDown) { web_event_type = blink::WebInputEvent::RawKeyDown; } else { - return Response::InvalidParams( - base::StringPrintf("Unexpected event type '%s'", type.c_str())); + callback->sendFailure(Response::InvalidParams( + base::StringPrintf("Unexpected event type '%s'", type.c_str()))); + return; } NativeWebKeyboardEvent event( @@ -260,10 +287,15 @@ is_keypad.fromMaybe(false)), GetEventTimeTicks(std::move(timestamp))); event.skip_in_browser = true; - if (!SetKeyboardEventText(event.text, std::move(text))) - return Response::InvalidParams("Invalid 'text' parameter"); - if (!SetKeyboardEventText(event.unmodifiedText, std::move(unmodified_text))) - return Response::InvalidParams("Invalid 'unmodifiedText' parameter"); + if (!SetKeyboardEventText(event.text, std::move(text))) { + callback->sendFailure(Response::InvalidParams("Invalid 'text' parameter")); + return; + } + if (!SetKeyboardEventText(event.unmodifiedText, std::move(unmodified_text))) { + callback->sendFailure( + Response::InvalidParams("Invalid 'unmodifiedText' parameter")); + return; + } if (windows_virtual_key_code.isJust()) event.windowsKeyCode = windows_virtual_key_code.fromJust(); @@ -282,33 +314,44 @@ ui::KeycodeConverter::KeyStringToDomKey(key.fromJust())); } - if (!host_ || !host_->GetRenderWidgetHost()) - return Response::InternalError(); + if (!host_ || !host_->GetRenderWidgetHost()) { + callback->sendFailure(Response::InternalError()); + return; + } host_->GetRenderWidgetHost()->Focus(); + input_queued_ = false; + pending_key_callbacks_.push_back(std::move(callback)); host_->GetRenderWidgetHost()->ForwardKeyboardEvent(event); - return Response::OK(); + if (!input_queued_) { + pending_key_callbacks_.back()->sendSuccess(); + pending_key_callbacks_.pop_back(); + } } -Response InputHandler::DispatchMouseEvent( +void InputHandler::DispatchMouseEvent( const std::string& type, int x, int y, Maybe<int> modifiers, Maybe<double> timestamp, Maybe<std::string> button, - Maybe<int> click_count) { + Maybe<int> click_count, + std::unique_ptr<DispatchMouseEventCallback> callback) { blink::WebInputEvent::Type event_type = GetMouseEventType(type); if (event_type == blink::WebInputEvent::Undefined) { - return Response::InvalidParams( - base::StringPrintf("Unexpected event type '%s'", type.c_str())); + callback->sendFailure(Response::InvalidParams( + base::StringPrintf("Unexpected event type '%s'", type.c_str()))); + return; } blink::WebPointerProperties::Button event_button = blink::WebPointerProperties::Button::NoButton; int button_modifiers = 0; if (!GetMouseEventButton(button.fromMaybe(""), &event_button, - &button_modifiers)) - return Response::InvalidParams("Invalid mouse button"); + &button_modifiers)) { + callback->sendFailure(Response::InvalidParams("Invalid mouse button")); + return; + } blink::WebMouseEvent event( event_type, @@ -328,11 +371,20 @@ event.pointerType = blink::WebPointerProperties::PointerType::Mouse; if (!host_ || !host_->GetRenderWidgetHost()) - return Response::InternalError(); + callback->sendFailure(Response::InternalError()); host_->GetRenderWidgetHost()->Focus(); + input_queued_ = false; + pending_mouse_callbacks_.push_back(std::move(callback)); host_->GetRenderWidgetHost()->ForwardMouseEvent(event); - return Response::OK(); + // MouseUp/Down events don't create a round-trip to the renderer, so there's + // no point in blocking the response until an ack is received. Only wait for + // an ack if we're synthesizing a MouseMove event, which does make a + // round-trip to the renderer. + if (event_type != blink::WebInputEvent::MouseMove || !input_queued_) { + pending_mouse_callbacks_.back()->sendSuccess(); + pending_mouse_callbacks_.pop_back(); + } } Response InputHandler::EmulateTouchFromMouseEvent(const std::string& type, @@ -587,5 +639,14 @@ } } +void InputHandler::ClearPendingKeyAndMouseCallbacks() { + for (auto& callback : pending_key_callbacks_) + callback->sendSuccess(); + pending_key_callbacks_.clear(); + for (auto& callback : pending_mouse_callbacks_) + callback->sendSuccess(); + pending_mouse_callbacks_.clear(); +} + } // namespace protocol } // namespace content
diff --git a/content/browser/devtools/protocol/input_handler.h b/content/browser/devtools/protocol/input_handler.h index 098f1ed..78b975e 100644 --- a/content/browser/devtools/protocol/input_handler.h +++ b/content/browser/devtools/protocol/input_handler.h
@@ -11,6 +11,7 @@ #include "content/browser/devtools/protocol/input.h" #include "content/browser/renderer_host/input/synthetic_gesture.h" #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" +#include "content/public/browser/render_widget_host.h" #include "ui/gfx/geometry/size_f.h" namespace cc { @@ -25,7 +26,8 @@ namespace protocol { class InputHandler : public DevToolsDomainHandler, - public Input::Backend { + public Input::Backend, + public RenderWidgetHost::InputEventObserver { public: InputHandler(); ~InputHandler() override; @@ -37,27 +39,31 @@ void OnSwapCompositorFrame(const cc::CompositorFrameMetadata& frame_metadata); Response Disable() override; - Response DispatchKeyEvent(const std::string& type, - Maybe<int> modifiers, - Maybe<double> timestamp, - Maybe<std::string> text, - Maybe<std::string> unmodified_text, - Maybe<std::string> key_identifier, - Maybe<std::string> code, - Maybe<std::string> key, - Maybe<int> windows_virtual_key_code, - Maybe<int> native_virtual_key_code, - Maybe<bool> auto_repeat, - Maybe<bool> is_keypad, - Maybe<bool> is_system_key) override; + void DispatchKeyEvent( + const std::string& type, + Maybe<int> modifiers, + Maybe<double> timestamp, + Maybe<std::string> text, + Maybe<std::string> unmodified_text, + Maybe<std::string> key_identifier, + Maybe<std::string> code, + Maybe<std::string> key, + Maybe<int> windows_virtual_key_code, + Maybe<int> native_virtual_key_code, + Maybe<bool> auto_repeat, + Maybe<bool> is_keypad, + Maybe<bool> is_system_key, + std::unique_ptr<DispatchKeyEventCallback> callback) override; - Response DispatchMouseEvent(const std::string& type, - int x, - int y, - Maybe<int> modifiers, - Maybe<double> timestamp, - Maybe<std::string> button, - Maybe<int> click_count) override; + void DispatchMouseEvent( + const std::string& type, + int x, + int y, + Maybe<int> modifiers, + Maybe<double> timestamp, + Maybe<std::string> button, + Maybe<int> click_count, + std::unique_ptr<DispatchMouseEventCallback> callback) override; Response EmulateTouchFromMouseEvent(const std::string& type, int x, @@ -101,6 +107,10 @@ std::unique_ptr<SynthesizeTapGestureCallback> callback) override; private: + // InputEventObserver + void OnInputEvent(const blink::WebInputEvent& event) override; + void OnInputEventAck(const blink::WebInputEvent& event) override; + void SynthesizeRepeatingScroll( SyntheticSmoothScrollGestureParams gesture_params, int repeat_count, @@ -118,7 +128,15 @@ std::unique_ptr<SynthesizeScrollGestureCallback> callback, SyntheticGesture::Result result); + void ClearPendingKeyAndMouseCallbacks(); + RenderFrameHostImpl* host_; + // Callbacks for calls to Input.dispatchKey/MouseEvent that have been sent to + // the renderer, but that we haven't yet received an ack for. + bool input_queued_; + std::deque<std::unique_ptr<DispatchKeyEventCallback>> pending_key_callbacks_; + std::deque<std::unique_ptr<DispatchMouseEventCallback>> + pending_mouse_callbacks_; float page_scale_factor_; gfx::SizeF scrollable_viewport_size_; int last_id_;
diff --git a/content/browser/devtools/protocol_config.json b/content/browser/devtools/protocol_config.json index 0039415..6dbb32d 100644 --- a/content/browser/devtools/protocol_config.json +++ b/content/browser/devtools/protocol_config.json
@@ -22,7 +22,7 @@ { "domain": "Input", "exclude": ["dispatchTouchEvent"], - "async": ["synthesizePinchGesture", "synthesizeScrollGesture", "synthesizeTapGesture"] + "async": ["dispatchKeyEvent", "dispatchMouseEvent", "synthesizePinchGesture", "synthesizeScrollGesture", "synthesizeTapGesture"] }, { "domain": "Inspector"
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index 235b2565..ea32701 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -2154,6 +2154,8 @@ const NativeWebKeyboardEventWithLatencyInfo& event, InputEventAckState ack_result) { latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result); + for (auto& input_event_observer : input_event_observers_) + input_event_observer.OnInputEventAck(event.event); const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); @@ -2174,6 +2176,8 @@ InputEventAckState ack_result) { latency_tracker_.OnInputEventAck(mouse_event.event, &mouse_event.latency, ack_result); + for (auto& input_event_observer : input_event_observers_) + input_event_observer.OnInputEventAck(mouse_event.event); } void RenderWidgetHostImpl::OnWheelEventAck( @@ -2181,6 +2185,8 @@ InputEventAckState ack_result) { latency_tracker_.OnInputEventAck(wheel_event.event, &wheel_event.latency, ack_result); + for (auto& input_event_observer : input_event_observers_) + input_event_observer.OnInputEventAck(wheel_event.event); if (!is_hidden() && view_) { if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED && @@ -2195,6 +2201,8 @@ const GestureEventWithLatencyInfo& event, InputEventAckState ack_result) { latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result); + for (auto& input_event_observer : input_event_observers_) + input_event_observer.OnInputEventAck(event.event); if (view_) view_->GestureEventAck(event.event, ack_result); @@ -2204,6 +2212,8 @@ const TouchEventWithLatencyInfo& event, InputEventAckState ack_result) { latency_tracker_.OnInputEventAck(event.event, &event.latency, ack_result); + for (auto& input_event_observer : input_event_observers_) + input_event_observer.OnInputEventAck(event.event); if (touch_emulator_ && touch_emulator_->HandleTouchEventAck(event.event, ack_result)) {
diff --git a/content/child/site_isolation_stats_gatherer_browsertest.cc b/content/child/site_isolation_stats_gatherer_browsertest.cc index 9150a97a..83be8459 100644 --- a/content/child/site_isolation_stats_gatherer_browsertest.cc +++ b/content/child/site_isolation_stats_gatherer_browsertest.cc
@@ -23,7 +23,9 @@ // resources from other websites, not constrained by the Same Origin Policy. We // are trying to verify that the renderer cannot fetch any cross-site document // responses even when the Same Origin Policy is turned off inside the renderer. -class SiteIsolationStatsGathererBrowserTest : public ContentBrowserTest { +class SiteIsolationStatsGathererBrowserTest + : public ContentBrowserTest, + public testing::WithParamInterface<bool> { public: SiteIsolationStatsGathererBrowserTest() {} ~SiteIsolationStatsGathererBrowserTest() override {} @@ -46,6 +48,11 @@ // Since we assume exploited renderer process, it can bypass the same origin // policy at will. Simulate that by passing the disable-web-security flag. command_line->AppendSwitch(switches::kDisableWebSecurity); + + if (GetParam()) { + command_line->AppendSwitchASCII("--enable-blink-features", + "LoadingWithMojo"); + } } void SetUpOnMainThread() override { @@ -124,7 +131,7 @@ DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGathererBrowserTest); }; -IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, +IN_PROC_BROWSER_TEST_P(SiteIsolationStatsGathererBrowserTest, CrossSiteDocumentBlockingForMimeType) { // Load a page that issues illegal cross-site document requests to bar.com. // The page uses XHR to request HTML/XML/JSON documents from bar.com, and @@ -193,7 +200,7 @@ } } -IN_PROC_BROWSER_TEST_F(SiteIsolationStatsGathererBrowserTest, +IN_PROC_BROWSER_TEST_P(SiteIsolationStatsGathererBrowserTest, CrossSiteDocumentBlockingForDifferentTargets) { // This webpage loads a cross-site HTML page in different targets such as // <img>,<link>,<embed>, etc. Since the requested document is blocked, and one @@ -208,4 +215,8 @@ NavigateToURL(shell(), foo); } +INSTANTIATE_TEST_CASE_P(SiteIsolationStatsGathererBrowserTest, + SiteIsolationStatsGathererBrowserTest, + ::testing::Values(false, true)); + } // namespace content
diff --git a/content/child/url_response_body_consumer.cc b/content/child/url_response_body_consumer.cc index 398ea85b1..cb89be51 100644 --- a/content/child/url_response_body_consumer.cc +++ b/content/child/url_response_body_consumer.cc
@@ -9,12 +9,15 @@ #include "base/macros.h" #include "base/memory/ptr_util.h" #include "content/child/resource_dispatcher.h" +#include "content/child/site_isolation_stats_gatherer.h" #include "content/common/resource_messages.h" #include "content/common/resource_request_completion_status.h" #include "content/public/child/request_peer.h" namespace content { +constexpr uint32_t URLResponseBodyConsumer::kMaxNumConsumedBytesInTask; + class URLResponseBodyConsumer::ReceivedData final : public RequestPeer::ReceivedData { public: @@ -98,6 +101,7 @@ return; DCHECK(!is_in_on_readable_); + uint32_t num_bytes_consumed = 0; // Protect |this| as RequestPeer::OnReceivedData may call deref. scoped_refptr<URLResponseBodyConsumer> protect(this); @@ -122,9 +126,33 @@ NotifyCompletionIfAppropriate(); return; } + DCHECK_LE(num_bytes_consumed, kMaxNumConsumedBytesInTask); + available = + std::min(available, kMaxNumConsumedBytesInTask - num_bytes_consumed); + if (available == 0) { + // We've already consumed many bytes in this task. Defer the remaining + // to the next task. + result = mojo::EndReadDataRaw(handle_.get(), 0); + DCHECK_EQ(result, MOJO_RESULT_OK); + task_runner_->PostTask(FROM_HERE, + base::Bind(&URLResponseBodyConsumer::OnReadable, + AsWeakPtr(), MOJO_RESULT_OK)); + return; + } + num_bytes_consumed += available; ResourceDispatcher::PendingRequestInfo* request_info = resource_dispatcher_->GetPendingRequestInfo(request_id_); DCHECK(request_info); + + // Check whether this response data is compliant with our cross-site + // document blocking policy. We only do this for the first chunk of data. + if (request_info->site_isolation_metadata.get()) { + SiteIsolationStatsGatherer::OnReceivedFirstChunk( + request_info->site_isolation_metadata, + static_cast<const char*>(buffer), available); + request_info->site_isolation_metadata.reset(); + } + request_info->peer->OnReceivedData(base::MakeUnique<ReceivedData>( static_cast<const char*>(buffer), available, this)); }
diff --git a/content/child/url_response_body_consumer.h b/content/child/url_response_body_consumer.h index b35abc8..1c33aaa 100644 --- a/content/child/url_response_body_consumer.h +++ b/content/child/url_response_body_consumer.h
@@ -51,6 +51,13 @@ void SetDefersLoading(); void UnsetDefersLoading(); + // The maximal number of bytes consumed in a task. When there are more bytes + // in the data pipe, they will be consumed in following tasks. Setting a too + // small number will generate ton of tasks but setting a too large number will + // lead to thread janks. Also, some clients cannot handle too large chunks + // (512k for example). + static constexpr uint32_t kMaxNumConsumedBytesInTask = 64 * 1024; + private: friend class base::RefCounted<URLResponseBodyConsumer>; ~URLResponseBodyConsumer();
diff --git a/content/child/url_response_body_consumer_unittest.cc b/content/child/url_response_body_consumer_unittest.cc index c77ba15..37d93ed 100644 --- a/content/child/url_response_body_consumer_unittest.cc +++ b/content/child/url_response_body_consumer_unittest.cc
@@ -265,6 +265,45 @@ EXPECT_EQ("", context.data); } +TEST_F(URLResponseBodyConsumerTest, TooBigChunkShouldBeSplit) { + constexpr auto kMaxNumConsumedBytesInTask = + URLResponseBodyConsumer::kMaxNumConsumedBytesInTask; + TestRequestPeer::Context context; + std::unique_ptr<ResourceRequest> request(CreateResourceRequest()); + int request_id = SetUpRequestPeer(std::move(request), &context); + auto options = CreateDataPipeOptions(); + options.capacity_num_bytes = 2 * kMaxNumConsumedBytesInTask; + mojo::DataPipe data_pipe(options); + + mojo::ScopedDataPipeProducerHandle writer = + std::move(data_pipe.producer_handle); + void* buffer = nullptr; + uint32_t size = 0; + MojoResult result = + mojo::BeginWriteDataRaw(writer.get(), &buffer, &size, kNone); + + ASSERT_EQ(MOJO_RESULT_OK, result); + ASSERT_EQ(options.capacity_num_bytes, size); + + memset(buffer, 'a', kMaxNumConsumedBytesInTask); + memset(static_cast<char*>(buffer) + kMaxNumConsumedBytesInTask, 'b', + kMaxNumConsumedBytesInTask); + + result = mojo::EndWriteDataRaw(writer.get(), size); + ASSERT_EQ(MOJO_RESULT_OK, result); + + scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( + request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), + message_loop_.task_runner())); + + Run(&context); + EXPECT_EQ(std::string(kMaxNumConsumedBytesInTask, 'a'), context.data); + context.data.clear(); + + Run(&context); + EXPECT_EQ(std::string(kMaxNumConsumedBytesInTask, 'b'), context.data); +} + } // namespace } // namespace content
diff --git a/content/public/browser/render_widget_host.h b/content/public/browser/render_widget_host.h index 4ddfd3c..8aa6a7b 100644 --- a/content/public/browser/render_widget_host.h +++ b/content/public/browser/render_widget_host.h
@@ -244,12 +244,13 @@ virtual void AddMouseEventCallback(const MouseEventCallback& callback) = 0; virtual void RemoveMouseEventCallback(const MouseEventCallback& callback) = 0; - // Observer for WebInputEvents (but not input event acks). + // Observer for WebInputEvents. class InputEventObserver { public: virtual ~InputEventObserver() {} - virtual void OnInputEvent(const blink::WebInputEvent&) = 0; + virtual void OnInputEvent(const blink::WebInputEvent&) {}; + virtual void OnInputEventAck(const blink::WebInputEvent&) {}; }; // Add/remove an input event observer.
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc index 921e8bf..bdf2af3 100644 --- a/content/public/test/browser_test_utils.cc +++ b/content/public/test/browser_test_utils.cc
@@ -1536,9 +1536,13 @@ return false; } +bool InputMsgWatcher::HasReceivedAck() const { + return ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN; +} + uint32_t InputMsgWatcher::WaitForAck() { DCHECK_CURRENTLY_ON(BrowserThread::UI); - if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) + if (HasReceivedAck()) return ack_result_; base::RunLoop run_loop; base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure());
diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h index 684d1c94..2d9832d0 100644 --- a/content/public/test/browser_test_utils.h +++ b/content/public/test/browser_test_utils.h
@@ -558,6 +558,8 @@ InputMsgWatcher(RenderWidgetHost* render_widget_host, blink::WebInputEvent::Type type); + bool HasReceivedAck() const; + // Wait until ack message occurs, returning the ack result from // the message. uint32_t WaitForAck();
diff --git a/content/renderer/OWNERS b/content/renderer/OWNERS index 62753f5..502a1a2 100644 --- a/content/renderer/OWNERS +++ b/content/renderer/OWNERS
@@ -11,8 +11,3 @@ # DirectWrite specific changes. per-file renderer_font_platform_win.*=scottmg@chromium.org per-file renderer_font_platform_win.*=cpu@chromium.org - -# WebSocket -per-file *websocket*=ricea@chromium.org -per-file *websocket*=tyoshino@chromium.org -per-file *websocket*=yhirano@chromium.org
diff --git a/content/renderer/media/media_recorder_handler_unittest.cc b/content/renderer/media/media_recorder_handler_unittest.cc index 6d6d6d0..9903f1b 100644 --- a/content/renderer/media/media_recorder_handler_unittest.cc +++ b/content/renderer/media/media_recorder_handler_unittest.cc
@@ -148,44 +148,44 @@ // Checks that canSupportMimeType() works as expected, by sending supported // combinations and unsupported ones. TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) { - const WebString unsupported_mime_type(base::UTF8ToUTF16("video/mpeg")); + const WebString unsupported_mime_type(WebString::fromASCII("video/mpeg")); EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( unsupported_mime_type, WebString())); - const WebString mime_type_video(base::UTF8ToUTF16("video/webm")); + const WebString mime_type_video(WebString::fromASCII("video/webm")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_video, WebString())); - const WebString mime_type_video_uppercase(base::UTF8ToUTF16("video/WEBM")); + const WebString mime_type_video_uppercase(WebString::fromASCII("video/WEBM")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_video_uppercase, WebString())); - const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); + const WebString example_good_codecs_1(WebString::fromASCII("vp8")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_video, example_good_codecs_1)); - const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); + const WebString example_good_codecs_2(WebString::fromASCII("vp9,opus")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_video, example_good_codecs_2)); - const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); + const WebString example_good_codecs_3(WebString::fromASCII("VP9,opus")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_video, example_good_codecs_3)); - const WebString example_good_codecs_4(base::UTF8ToUTF16("H264")); + const WebString example_good_codecs_4(WebString::fromASCII("H264")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_video, example_good_codecs_4)); - const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); + const WebString example_unsupported_codecs_1(WebString::fromASCII("daala")); EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( mime_type_video, example_unsupported_codecs_1)); - const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); + const WebString mime_type_audio(WebString::fromASCII("audio/webm")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_audio, WebString())); - const WebString example_good_codecs_5(base::UTF8ToUTF16("opus")); + const WebString example_good_codecs_5(WebString::fromASCII("opus")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_audio, example_good_codecs_5)); - const WebString example_good_codecs_6(base::UTF8ToUTF16("OpUs")); + const WebString example_good_codecs_6(WebString::fromASCII("OpUs")); EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( mime_type_audio, example_good_codecs_6)); - const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); + const WebString example_unsupported_codecs_2(WebString::fromASCII("vorbis")); EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( mime_type_audio, example_unsupported_codecs_2)); } @@ -193,8 +193,8 @@ // Checks that the initialization-destruction sequence works fine. TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { AddTracks(); - const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); - const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); + const WebString mime_type(WebString::fromASCII(GetParam().mime_type)); + const WebString codecs(WebString::fromASCII(GetParam().codecs)); EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), mime_type, codecs, 0, 0)); EXPECT_FALSE(recording()); @@ -225,8 +225,8 @@ AddTracks(); - const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); - const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); + const WebString mime_type(WebString::fromASCII(GetParam().mime_type)); + const WebString codecs(WebString::fromASCII(GetParam().codecs)); EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), mime_type, codecs, 0, 0)); EXPECT_TRUE(media_recorder_handler_->start(0)); @@ -287,7 +287,7 @@ AddTracks(); - const WebString mime_type(base::UTF8ToUTF16("audio/webm")); + const WebString mime_type(WebString::fromASCII("audio/webm")); EXPECT_TRUE(media_recorder_handler_->initialize( this, registry_.test_stream(), mime_type, WebString(), 0, 0)); EXPECT_TRUE(media_recorder_handler_->start(0)); @@ -351,8 +351,8 @@ AddTracks(); - const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); - const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); + const WebString mime_type(WebString::fromASCII(GetParam().mime_type)); + const WebString codecs(WebString::fromASCII(GetParam().codecs)); EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), mime_type, codecs, 0, 0)); EXPECT_TRUE(media_recorder_handler_->start(0));
diff --git a/content/renderer/media/media_stream_video_capturer_source_unittest.cc b/content/renderer/media/media_stream_video_capturer_source_unittest.cc index abe18be..8912961 100644 --- a/content/renderer/media/media_stream_video_capturer_source_unittest.cc +++ b/content/renderer/media/media_stream_video_capturer_source_unittest.cc
@@ -83,9 +83,9 @@ std::move(delegate)); source_->SetDeviceInfo(device_info); - webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), false /* remote */); webkit_source_.setExtraData(source_); webkit_source_id_ = webkit_source_.id(); @@ -298,9 +298,9 @@ base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, base::Unretained(this)), std::move(delegate)); - webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), false /* remote */); webkit_source_.setExtraData(source_); webkit_source_id_ = webkit_source_.id();
diff --git a/content/renderer/media/media_stream_video_renderer_sink_unittest.cc b/content/renderer/media/media_stream_video_renderer_sink_unittest.cc index 3318f2b..b4343c1c 100644 --- a/content/renderer/media/media_stream_video_renderer_sink_unittest.cc +++ b/content/renderer/media/media_stream_video_renderer_sink_unittest.cc
@@ -36,9 +36,9 @@ MediaStreamVideoRendererSinkTest() : child_process_(new ChildProcess()), mock_source_(new MockMediaStreamVideoSource(false)) { - blink_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + blink_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), false /* remote */); blink_source_.setExtraData(mock_source_); blink::WebMediaConstraints constraints;
diff --git a/content/renderer/media/media_stream_video_source_unittest.cc b/content/renderer/media/media_stream_video_source_unittest.cc index dfeea8e..9f21b460 100644 --- a/content/renderer/media/media_stream_video_source_unittest.cc +++ b/content/renderer/media/media_stream_video_source_unittest.cc
@@ -50,9 +50,9 @@ formats.push_back(media::VideoCaptureFormat( gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420)); mock_source_->SetSupportedFormats(formats); - webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), false /* remote */); webkit_source_.setExtraData(mock_source_); }
diff --git a/content/renderer/media/media_stream_video_track_unittest.cc b/content/renderer/media/media_stream_video_track_unittest.cc index 85b7bda..d95e14c 100644 --- a/content/renderer/media/media_stream_video_track_unittest.cc +++ b/content/renderer/media/media_stream_video_track_unittest.cc
@@ -34,9 +34,9 @@ : child_process_(new ChildProcess()), mock_source_(new MockMediaStreamVideoSource(false)), source_started_(false) { - blink_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + blink_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), false /* remote */); blink_source_.setExtraData(mock_source_); } @@ -85,9 +85,9 @@ void UpdateVideoSourceToRespondToRequestRefreshFrame() { blink_source_.reset(); mock_source_ = new MockMediaStreamVideoSource(false, true); - blink_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + blink_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), false /* remote */); blink_source_.setExtraData(mock_source_); }
diff --git a/content/renderer/media/mock_media_stream_registry.cc b/content/renderer/media/mock_media_stream_registry.cc index ecc1af5..96e6671 100644 --- a/content/renderer/media/mock_media_stream_registry.cc +++ b/content/renderer/media/mock_media_stream_registry.cc
@@ -67,7 +67,7 @@ new MockMediaStreamVideoSource(false /* manual get supported formats */); blink_source.setExtraData(native_source); blink::WebMediaStreamTrack blink_track; - blink_track.initialize(base::UTF8ToUTF16(track_id), blink_source); + blink_track.initialize(blink::WebString::fromUTF8(track_id), blink_source); MediaStreamVideoTrack* native_track = new MediaStreamVideoTrack( native_source, constraints, MediaStreamVideoSource::ConstraintsCallback(),
diff --git a/content/renderer/media/rtc_peer_connection_handler_unittest.cc b/content/renderer/media/rtc_peer_connection_handler_unittest.cc index 4112762..8f1dbcd 100644 --- a/content/renderer/media/rtc_peer_connection_handler_unittest.cc +++ b/content/renderer/media/rtc_peer_connection_handler_unittest.cc
@@ -335,8 +335,8 @@ MediaStreamVideoSource::ConstraintsCallback(), true); blink::WebMediaStream local_stream; - local_stream.initialize(base::UTF8ToUTF16(stream_label), audio_tracks, - video_tracks); + local_stream.initialize(blink::WebString::fromUTF8(stream_label), + audio_tracks, video_tracks); local_stream.setExtraData(new MediaStream()); return local_stream; } @@ -1010,23 +1010,29 @@ AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); testing::InSequence sequence; - EXPECT_CALL(*mock_tracker_.get(), TrackAddStream( - pc_handler_.get(), - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)), - PeerConnectionTracker::SOURCE_REMOTE)); - EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)))); + EXPECT_CALL( + *mock_tracker_.get(), + TrackAddStream( + pc_handler_.get(), + testing::Property(&blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)), + PeerConnectionTracker::SOURCE_REMOTE)); + EXPECT_CALL(*mock_client_.get(), + didAddRemoteStream(testing::Property( + &blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)))); - EXPECT_CALL(*mock_tracker_.get(), TrackRemoveStream( - pc_handler_.get(), - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)), - PeerConnectionTracker::SOURCE_REMOTE)); - EXPECT_CALL(*mock_client_.get(), didRemoveRemoteStream( - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)))); + EXPECT_CALL( + *mock_tracker_.get(), + TrackRemoveStream( + pc_handler_.get(), + testing::Property(&blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)), + PeerConnectionTracker::SOURCE_REMOTE)); + EXPECT_CALL(*mock_client_.get(), + didRemoveRemoteStream(testing::Property( + &blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)))); pc_handler_->observer()->OnAddStream(remote_stream); base::RunLoop().RunUntilIdle(); @@ -1041,9 +1047,10 @@ AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); testing::InSequence sequence; - EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)))); + EXPECT_CALL(*mock_client_.get(), + didAddRemoteStream(testing::Property( + &blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)))); pc_handler_->observer()->OnAddStream(remote_stream); base::RunLoop().RunUntilIdle(); const blink::WebMediaStream& webkit_stream = mock_client_->remote_stream(); @@ -1077,12 +1084,12 @@ // Grab the added media stream when it's been successfully added to the PC. blink::WebMediaStream webkit_stream; - EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)))) - .WillOnce( - DoAll(SaveArg<0>(&webkit_stream), - ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); + EXPECT_CALL(*mock_client_.get(), + didAddRemoteStream(testing::Property( + &blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)))) + .WillOnce(DoAll(SaveArg<0>(&webkit_stream), + ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); @@ -1125,12 +1132,12 @@ // Grab the added media stream when it's been successfully added to the PC. blink::WebMediaStream webkit_stream; - EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)))) - .WillOnce( - DoAll(SaveArg<0>(&webkit_stream), - ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); + EXPECT_CALL(*mock_client_.get(), + didAddRemoteStream(testing::Property( + &blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)))) + .WillOnce(DoAll(SaveArg<0>(&webkit_stream), + ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( AddRemoteMockMediaStream(remote_stream_label, "video", "audio")); @@ -1172,12 +1179,12 @@ // Grab the added media stream when it's been successfully added to the PC. blink::WebMediaStream webkit_stream; - EXPECT_CALL(*mock_client_.get(), didAddRemoteStream( - testing::Property(&blink::WebMediaStream::id, - base::UTF8ToUTF16(remote_stream_label)))) - .WillOnce( - DoAll(SaveArg<0>(&webkit_stream), - ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); + EXPECT_CALL(*mock_client_.get(), + didAddRemoteStream(testing::Property( + &blink::WebMediaStream::id, + blink::WebString::fromASCII(remote_stream_label)))) + .WillOnce(DoAll(SaveArg<0>(&webkit_stream), + ExitMessageLoop(&message_loop_, run_loop.QuitClosure()))); rtc::scoped_refptr<webrtc::MediaStreamInterface> remote_stream( AddRemoteMockMediaStream(remote_stream_label, "video", "audio"));
diff --git a/content/renderer/media/video_track_recorder_unittest.cc b/content/renderer/media/video_track_recorder_unittest.cc index bffe055..97bfa40 100644 --- a/content/renderer/media/video_track_recorder_unittest.cc +++ b/content/renderer/media/video_track_recorder_unittest.cc
@@ -61,7 +61,8 @@ public: VideoTrackRecorderTest() : mock_source_(new MockMediaStreamVideoSource(false)) { - const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy")); + const blink::WebString webkit_track_id( + blink::WebString::fromASCII("dummy")); blink_source_.initialize(webkit_track_id, blink::WebMediaStreamSource::TypeVideo, webkit_track_id);
diff --git a/content/renderer/media/webrtc/media_stream_remote_video_source_unittest.cc b/content/renderer/media/webrtc/media_stream_remote_video_source_unittest.cc index 64e0da1..6752973 100644 --- a/content/renderer/media/webrtc/media_stream_remote_video_source_unittest.cc +++ b/content/renderer/media/webrtc/media_stream_remote_video_source_unittest.cc
@@ -47,9 +47,9 @@ webrtc_video_track_.get())))), number_of_successful_constraints_applied_(0), number_of_failed_constraints_applied_(0) { - webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), + webkit_source_.initialize(blink::WebString::fromASCII("dummy_source_id"), blink::WebMediaStreamSource::TypeVideo, - base::UTF8ToUTF16("dummy_source_name"), + blink::WebString::fromASCII("dummy_source_name"), true /* remote */); webkit_source_.setExtraData(remote_source_); }
diff --git a/content/renderer/pepper/OWNERS b/content/renderer/pepper/OWNERS index 3d24b44..332f3e7 100644 --- a/content/renderer/pepper/OWNERS +++ b/content/renderer/pepper/OWNERS
@@ -4,3 +4,8 @@ per-file plugin_power_saver*=tommycli@chromium.org per-file usb_key_code_*=garykac@chromium.org per-file usb_key_code_*=wez@chromium.org + +# WebSocket +per-file *websocket*=ricea@chromium.org +per-file *websocket*=tyoshino@chromium.org +per-file *websocket*=yhirano@chromium.org
diff --git a/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java b/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java index c29dfe3..f83cb43 100644 --- a/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java +++ b/device/power_save_blocker/android/java/src/org/chromium/device/power_save_blocker/PowerSaveBlocker.java
@@ -24,21 +24,21 @@ private PowerSaveBlocker() {} @CalledByNative - private void applyBlock(View anchorView) { + private void applyBlock(View view) { assert mKeepScreenOnView == null; - mKeepScreenOnView = new WeakReference<>(anchorView); - anchorView.setKeepScreenOn(true); + mKeepScreenOnView = new WeakReference<>(view); + view.setKeepScreenOn(true); } @CalledByNative private void removeBlock() { - // mKeepScreenOnView may be null since it's possible that |applyBlock()| - // was not invoked due to having failed to acquire an anchor view. + // mKeepScreenOnView may be null since it's possible that |applyBlock()| was + // not invoked due to having failed to get a view to call |setKeepScrenOn| on. if (mKeepScreenOnView == null) return; - View anchorView = mKeepScreenOnView.get(); + View view = mKeepScreenOnView.get(); mKeepScreenOnView = null; - if (anchorView == null) return; + if (view == null) return; - anchorView.setKeepScreenOn(false); + view.setKeepScreenOn(false); } }
diff --git a/device/power_save_blocker/power_save_blocker_android.cc b/device/power_save_blocker/power_save_blocker_android.cc index 4d6e3c574..c589035 100644 --- a/device/power_save_blocker/power_save_blocker_android.cc +++ b/device/power_save_blocker/power_save_blocker_android.cc
@@ -32,8 +32,6 @@ base::android::ScopedJavaGlobalRef<jobject> java_power_save_blocker_; - ui::ViewAndroid::ScopedAnchorView anchor_view_; - scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; DISALLOW_COPY_AND_ASSIGN(Delegate); @@ -52,21 +50,19 @@ DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); DCHECK(view_android); - JNIEnv* env = AttachCurrentThread(); - anchor_view_ = view_android->AcquireAnchorView(); - const ScopedJavaLocalRef<jobject> popup_view = anchor_view_.view(); - if (popup_view.is_null()) - return; - view_android->SetAnchorRect(popup_view, gfx::RectF()); ScopedJavaLocalRef<jobject> obj(java_power_save_blocker_); - Java_PowerSaveBlocker_applyBlock(env, obj, popup_view); + ScopedJavaLocalRef<jobject> container_view(view_android->GetContainerView()); + if (container_view.is_null()) + return; + + Java_PowerSaveBlocker_applyBlock(AttachCurrentThread(), obj, container_view); } void PowerSaveBlocker::Delegate::RemoveBlock() { DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); + ScopedJavaLocalRef<jobject> obj(java_power_save_blocker_); Java_PowerSaveBlocker_removeBlock(AttachCurrentThread(), obj); - anchor_view_.Reset(); } PowerSaveBlocker::PowerSaveBlocker(
diff --git a/media/filters/vp9_parser_fuzzertest.cc b/media/filters/vp9_parser_fuzzertest.cc index 075fae5..468a151 100644 --- a/media/filters/vp9_parser_fuzzertest.cc +++ b/media/filters/vp9_parser_fuzzertest.cc
@@ -9,6 +9,16 @@ #include "media/filters/ivf_parser.h" #include "media/filters/vp9_parser.h" +struct Environment { + Environment() { + // Disable noisy logging as per "libFuzzer in Chrome" documentation: + // testing/libfuzzer/getting_started.md#Disable-noisy-error-message-logging. + logging::SetMinLogLevel(logging::LOG_FATAL); + } +}; + +Environment* env = new Environment(); + // Entry point for LibFuzzer. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { const uint8_t* ivf_payload = nullptr;
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index 1b812c1..533c07b6 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc
@@ -274,7 +274,7 @@ } ChangeCausePair; const ChangeCausePair kChangeCauseMapping[] = { // DELETE_COOKIE_EXPLICIT - {CookieStore::ChangeCause::EXPLICIT_DELETE, true}, + {CookieStore::ChangeCause::EXPLICIT, true}, // DELETE_COOKIE_OVERWRITE {CookieStore::ChangeCause::OVERWRITE, true}, // DELETE_COOKIE_EXPIRED @@ -282,9 +282,9 @@ // DELETE_COOKIE_EVICTED {CookieStore::ChangeCause::EVICTED, true}, // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE - {CookieStore::ChangeCause::EXPLICIT_DUPLICATE_IN_BACKING_STORE, false}, + {CookieStore::ChangeCause::EXPLICIT, false}, // DELETE_COOKIE_DONT_RECORD - {CookieStore::ChangeCause::EXPLICIT_DONT_RECORD, false}, + {CookieStore::ChangeCause::EXPLICIT, false}, // DELETE_COOKIE_EVICTED_DOMAIN {CookieStore::ChangeCause::EVICTED, true}, // DELETE_COOKIE_EVICTED_GLOBAL @@ -299,8 +299,16 @@ {CookieStore::ChangeCause::EVICTED, true}, // DELETE_COOKIE_NON_SECURE {CookieStore::ChangeCause::EVICTED, true}, + // DELETE_COOKIE_CREATED_BETWEEN + {CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN, true}, + // DELETE_COOKIE_CREATED_BETWEEN_WITH_PREDICATE + {CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE, true}, + // DELETE_COOKIE_SINGLE + {CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE, true}, + // DELETE_COOKIE_CANONICAL + {CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL, true}, // DELETE_COOKIE_LAST_ENTRY - {CookieStore::ChangeCause::EXPLICIT_LAST_ENTRY, false}}; + {CookieStore::ChangeCause::EXPLICIT, false}}; void RunAsync(scoped_refptr<base::TaskRunner> proxy, const CookieStore::CookieChangedCallback& callback, @@ -1140,7 +1148,7 @@ if (cc->CreationDate() >= delete_begin && (delete_end.is_null() || cc->CreationDate() < delete_end)) { InternalDeleteCookie(curit, true, /*sync_to_store*/ - DELETE_COOKIE_EXPLICIT); + DELETE_COOKIE_CREATED_BETWEEN); ++num_deleted; } } @@ -1164,7 +1172,7 @@ (delete_end.is_null() || cc->CreationDate() < delete_end) && predicate.Run(*cc)) { InternalDeleteCookie(curit, true, /*sync_to_store*/ - DELETE_COOKIE_EXPLICIT); + DELETE_COOKIE_CREATED_BETWEEN_WITH_PREDICATE); ++num_deleted; } } @@ -1230,7 +1238,7 @@ CookieMap::iterator curit = it; ++it; if (matching_cookies.find(curit->second.get()) != matching_cookies.end()) { - InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); + InternalDeleteCookie(curit, true, DELETE_COOKIE_SINGLE); } } } @@ -1242,7 +1250,7 @@ its.first != its.second; ++its.first) { // The creation date acts as the unique index... if (its.first->second->CreationDate() == cookie.CreationDate()) { - InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT); + InternalDeleteCookie(its.first, true, DELETE_COOKIE_CANONICAL); return 1; } } @@ -1846,8 +1854,13 @@ "kChangeCauseMapping size should match DeletionCause size"); // See InitializeHistograms() for details. + DeletionCause deletion_cause_to_record = deletion_cause; + if (deletion_cause >= DELETE_COOKIE_CREATED_BETWEEN && + deletion_cause <= DELETE_COOKIE_CANONICAL) { + deletion_cause_to_record = DELETE_COOKIE_EXPLICIT; + } if (deletion_cause != DELETE_COOKIE_DONT_RECORD) - histogram_cookie_deletion_cause_->Add(deletion_cause); + histogram_cookie_deletion_cause_->Add(deletion_cause_to_record); CanonicalCookie* cc = it->second.get(); VLOG(kVlogSetCookies) << "InternalDeleteCookie()"
diff --git a/net/cookies/cookie_monster.h b/net/cookies/cookie_monster.h index d509c41..52d4320 100644 --- a/net/cookies/cookie_monster.h +++ b/net/cookies/cookie_monster.h
@@ -280,8 +280,11 @@ // the CookieStore::ChangeCause mapping inside ChangeCauseMapping. // Moreover, these are used as array indexes, so avoid reordering to keep the // histogram buckets consistent. New items (if necessary) should be added - // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. + // at the end of the list, before DELETE_COOKIE_LAST_ENTRY and the temporary + // values added for debugging. enum DeletionCause { + // DELETE_COOKIE_EXPLICIT is temporarily unused (except for logging to the + // histogram) - see values 13-16 below. DELETE_COOKIE_EXPLICIT = 0, DELETE_COOKIE_OVERWRITE = 1, DELETE_COOKIE_EXPIRED = 2, @@ -313,7 +316,18 @@ // right after expired cookies. DELETE_COOKIE_NON_SECURE = 12, - DELETE_COOKIE_LAST_ENTRY = 13 + // The following values are temporary and being used to track down a bug. + // They should be treated the same as DELETE_COOKIE_EXPLICIT, and are logged + // to the histogram as DELETE_COOKIE_EXPLICIT. + DELETE_COOKIE_CREATED_BETWEEN = 13, + DELETE_COOKIE_CREATED_BETWEEN_WITH_PREDICATE = 14, + DELETE_COOKIE_SINGLE = 15, + DELETE_COOKIE_CANONICAL = 16, + + // Do not add new values between DELETE_COOKIE_CREATED_BETWEEN and + // DELETE_COOKIE_LAST_ENTRY, as the above values are temporary. Instead, new + // values should go before DELETE_COOKIE_CREATED_BETWEEN. + DELETE_COOKIE_LAST_ENTRY = 17 }; // This enum is used to generate a histogramed bitmask measureing the types
diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc index 52812d3..7003288 100644 --- a/net/cookies/cookie_monster_unittest.cc +++ b/net/cookies/cookie_monster_unittest.cc
@@ -3398,7 +3398,7 @@ EXPECT_EQ("abc", cookies[1].Name()); EXPECT_EQ("def", cookies[1].Value()); - EXPECT_EQ(CookieStore::ChangeCause::EXPLICIT_DELETE, causes[1]); + EXPECT_EQ(CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE, causes[1]); } TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) {
diff --git a/net/cookies/cookie_store.h b/net/cookies/cookie_store.h index 63241b5..f81fa23a 100644 --- a/net/cookies/cookie_store.h +++ b/net/cookies/cookie_store.h
@@ -36,14 +36,15 @@ // The cookie was inserted. INSERTED, // The cookie was changed directly by a consumer's action. - // The following enum values all have the same meaning, but are being used - // to track down where a bug came from. - // TODO(nharper): Remove all but one of these and rename to EXPLICIT once - // the one of interest has been found. - EXPLICIT_DELETE, - EXPLICIT_DUPLICATE_IN_BACKING_STORE, - EXPLICIT_DONT_RECORD, - EXPLICIT_LAST_ENTRY, + EXPLICIT, + // The following four values have the same meaning as EXPLICIT, but are + // being used to track down where a bug is coming from. + // TODO(nharper): Remove the following four values once the one of interest + // has been found. + EXPLICIT_DELETE_BETWEEN, + EXPLICIT_DELETE_PREDICATE, + EXPLICIT_DELETE_SINGLE, + EXPLICIT_DELETE_CANONICAL, // The cookie was deleted, but no more details are known. UNKNOWN_DELETION, // The cookie was automatically removed due to an insert operation that
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index 7813e33..c57b238 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc
@@ -2088,13 +2088,8 @@ jobs[url2]->results()->UseNamedProxy("request2:80"); jobs[url2]->CompleteNow(OK); - //<<<<<<< HEAD - // // Complete and verify that requests ran as expected. - // EXPECT_THAT(callback1.WaitForResult(), IsOk()); - //======= // Complete and verify that jobs ran as expected. EXPECT_EQ(OK, callback1.WaitForResult()); - //>>>>>>> parent of 9c8f424... Revert of Change // ProxyResolver::GetProxyForURL() to take a std::unique_ptr<Request>* rather // than a RequestHandle* (patchset #11 id:200001 of // https://codereview.chromium.org/1439053002/ ) @@ -2337,13 +2332,8 @@ jobs[url1]->results()->UseNamedProxy("request1:80"); jobs[url1]->CompleteNow(OK); - //<<<<<<< HEAD - // // Verify that requests ran as expected. - // EXPECT_THAT(callback1.WaitForResult(), IsOk()); - //======= // Verify that jobs ran as expected. EXPECT_EQ(OK, callback1.WaitForResult()); - //>>>>>>> parent of 9c8f424... Revert of Change // ProxyResolver::GetProxyForURL() to take a std::unique_ptr<Request>* rather // than a RequestHandle* (patchset #11 id:200001 of // https://codereview.chromium.org/1439053002/ ) @@ -2427,13 +2417,8 @@ jobs[url1]->results()->UseNamedProxy("request1:80"); jobs[url1]->CompleteNow(OK); - //<<<<<<< HEAD - // // Verify that requests ran as expected. - // EXPECT_THAT(callback1.WaitForResult(), IsOk()); - //======= // Verify that jobs ran as expected. EXPECT_EQ(OK, callback1.WaitForResult()); - //>>>>>>> parent of 9c8f424... Revert of Change // ProxyResolver::GetProxyForURL() to take a std::unique_ptr<Request>* rather // than a RequestHandle* (patchset #11 id:200001 of // https://codereview.chromium.org/1439053002/ )
diff --git a/third_party/WebKit/LayoutTests/TestExpectations b/third_party/WebKit/LayoutTests/TestExpectations index 5074a2a..4d9f6fe 100644 --- a/third_party/WebKit/LayoutTests/TestExpectations +++ b/third_party/WebKit/LayoutTests/TestExpectations
@@ -1177,8 +1177,6 @@ crbug.com/651343 fast/text/international/inline-plaintext-relayout-with-leading-neutrals.html [ Pass Failure ] -crbug.com/385014 crbug.com/410145 accessibility/canvas-fallback-content-2.html [ Pass Failure Timeout ] - crbug.com/574283 [ Mac ] fast/scroll-behavior/smooth-scroll/ongoing-smooth-scroll-anchors.html [ Skip ] crbug.com/574283 [ Mac ] virtual/scroll_customization/fast/scroll-behavior/smooth-scroll/ongoing-smooth-scroll-anchors.html [ Skip ] crbug.com/574283 [ Mac ] virtual/threaded/fast/scroll-behavior/first-scroll-runs-on-compositor.html [ Skip ]
diff --git a/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2-expected.txt b/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2-expected.txt index eb95df6..7077bc5 100644 --- a/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2-expected.txt +++ b/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2-expected.txt
@@ -19,9 +19,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -36,9 +35,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -53,9 +51,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -70,9 +67,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -87,9 +83,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -104,9 +99,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -121,9 +115,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -138,9 +131,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -155,9 +147,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -172,9 +163,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -189,9 +179,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -206,9 +195,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -223,9 +211,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -240,9 +227,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -257,9 +243,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -274,9 +259,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -291,9 +275,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -308,9 +291,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -325,9 +307,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -342,9 +323,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired @@ -359,9 +339,8 @@ PASS document.activeElement == element2 is true PASS axElement2.role is axElement1.role PASS axElement2.roleDescription is axElement1.roleDescription -PASS axElement2.name is axElement1.deprecatedTitle -PASS axElement2.deprecatedDescription is axElement1.deprecatedDescription -PASS axElement2.deprecatedHelpText is axElement1.deprecatedHelpText +PASS axElement2.name is axElement1.name +PASS axElement2.description is axElement1.description PASS axElement2.stringValue is axElement1.stringValue PASS axElement2.isEnabled is axElement1.isEnabled PASS axElement2.isRequired is axElement1.isRequired
diff --git a/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2.html b/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2.html index c8158bfb..7ebac941 100644 --- a/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2.html +++ b/third_party/WebKit/LayoutTests/accessibility/canvas-fallback-content-2.html
@@ -74,8 +74,7 @@ shouldBe("axElement2.role", "axElement1.role"); shouldBe("axElement2.roleDescription", "axElement1.roleDescription"); shouldBe("axElement2.name", "axElement1.name"); - shouldBe("axElement2.name", "axElement1.name"); - shouldBe("axElement2.description", "axElement1.deprecatedHelpText"); + shouldBe("axElement2.description", "axElement1.description"); shouldBe("axElement2.stringValue", "axElement1.stringValue"); shouldBe("axElement2.isEnabled", "axElement1.isEnabled"); shouldBe("axElement2.isRequired", "axElement1.isRequired");
diff --git a/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-attributes.html b/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-attributes.html index f2db95a..306c4af4 100644 --- a/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-attributes.html +++ b/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-attributes.html
@@ -10,12 +10,9 @@ assert_equals(entries.length, 1, "Exactly one entry is expected."); var longtask = entries[0]; - assert_equals(longtask.entryType, "longtask", - "entryType expected to be: longtask"); - assert_equals(longtask.name, "same-origin-self", - "name expected to be: same-origin-self"); - assert_greater_than(longtask.duration, 50, - "duration expected to be greater than 50ms threshold"); + assert_equals(longtask.entryType, "longtask"); + assert_equals(longtask.name, "self"); + assert_greater_than(longtask.duration, 50); assert_equals(longtask.startTime, Math.floor(longtask.startTime), "startTime expected to have 1 miillisecond granularity"); @@ -24,7 +21,7 @@ "Exactly one attribution entry is expected"); var attribution = longtask.attribution[0]; assert_equals(attribution.entryType, "taskattribution"); - assert_equals(attribution.name, "frame"); + assert_equals(attribution.name, "script"); assert_equals(attribution.duration, 0); assert_equals(attribution.startTime, 0);
diff --git a/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-externalscript.html b/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-externalscript.html index 95334f2..503d0934 100644 --- a/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-externalscript.html +++ b/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-externalscript.html
@@ -11,12 +11,9 @@ assert_equals(entries.length, 1, "Exactly one entry is expected."); var longtask = entries[0]; - assert_equals(longtask.entryType, "longtask", - "entryType expected to be: longtask"); - assert_equals(longtask.name, "same-origin-self", - "name expected to be: same-origin-self"); - assert_greater_than(longtask.duration, 50, - "duration expected to be greater than 50ms threshold"); + assert_equals(longtask.entryType, "longtask"); + assert_equals(longtask.name, "self"); + assert_greater_than(longtask.duration, 50); assert_equals(longtask.startTime, Math.floor(longtask.startTime), "startTime expected to have 1 miillisecond granularity"); @@ -25,7 +22,7 @@ "Exactly one attribution entry is expected"); var attribution = longtask.attribution[0]; assert_equals(attribution.entryType, "taskattribution"); - assert_equals(attribution.name, "frame"); + assert_equals(attribution.name, "script"); assert_equals(attribution.duration, 0); assert_equals(attribution.startTime, 0);
diff --git a/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-raf.html b/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-raf.html index 7edb8451..2c54928 100644 --- a/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-raf.html +++ b/third_party/WebKit/LayoutTests/http/tests/performance-timing/longtask/longtask-raf.html
@@ -11,12 +11,9 @@ assert_equals(entries.length, 1, "Exactly one entry is expected."); var longtask = entries[0]; - assert_equals(longtask.entryType, "longtask", - "entryType expected to be: longtask"); - assert_equals(longtask.name, "same-origin-self", - "name expected to be: same-origin-self"); - assert_greater_than(longtask.duration, 50, - "duration expected to be greater than 50ms threshold"); + assert_equals(longtask.entryType, "longtask"); + assert_equals(longtask.name, "self"); + assert_greater_than(longtask.duration, 50); assert_equals(longtask.startTime, Math.floor(longtask.startTime), "startTime expected to have 1 miillisecond granularity"); @@ -25,7 +22,7 @@ "Exactly one attribution entry is expected"); var attribution = longtask.attribution[0]; assert_equals(attribution.entryType, "taskattribution"); - assert_equals(attribution.name, "frame"); + assert_equals(attribution.name, "script"); assert_equals(attribution.duration, 0); assert_equals(attribution.startTime, 0);
diff --git a/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt b/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt index de1ba1e..447bfb0 100644 --- a/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt +++ b/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt
@@ -6493,9 +6493,10 @@ method register interface TaskAttributionTiming : PerformanceEntry attribute @@toStringTag - getter frameId - getter frameName - getter frameSrc + getter containerId + getter containerName + getter containerSrc + getter containerType method constructor interface Text : CharacterData attribute @@toStringTag
diff --git a/third_party/WebKit/Source/core/BUILD.gn b/third_party/WebKit/Source/core/BUILD.gn index f646882..55be3580 100644 --- a/third_party/WebKit/Source/core/BUILD.gn +++ b/third_party/WebKit/Source/core/BUILD.gn
@@ -186,7 +186,6 @@ "//third_party/WebKit/Source/core/layout", "//third_party/WebKit/Source/core/layout/svg", "//third_party/WebKit/Source/core/loader", - "//third_party/WebKit/Source/core/observer", "//third_party/WebKit/Source/core/offscreencanvas", "//third_party/WebKit/Source/core/origin_trials", "//third_party/WebKit/Source/core/page",
diff --git a/third_party/WebKit/Source/core/core_idl_files.gni b/third_party/WebKit/Source/core/core_idl_files.gni index eb7930c..4bc37e3b4 100644 --- a/third_party/WebKit/Source/core/core_idl_files.gni +++ b/third_party/WebKit/Source/core/core_idl_files.gni
@@ -133,6 +133,9 @@ "dom/NodeList.idl", "dom/ProcessingInstruction.idl", "dom/Range.idl", + "dom/ResizeObserver.idl", + "dom/ResizeObserverCallback.idl", + "dom/ResizeObserverEntry.idl", "dom/SharedArrayBuffer.idl", "dom/StaticRange.idl", "dom/StringCallback.idl", @@ -286,9 +289,6 @@ "input/InputDeviceCapabilities.idl", "inspector/InspectorOverlayHost.idl", "loader/appcache/ApplicationCache.idl", - "observer/ResizeObserver.idl", - "observer/ResizeObserverCallback.idl", - "observer/ResizeObserverEntry.idl", "page/PagePopupController.idl", "page/scrolling/ScrollState.idl", "page/scrolling/ScrollStateCallback.idl",
diff --git a/third_party/WebKit/Source/core/css/BUILD.gn b/third_party/WebKit/Source/core/css/BUILD.gn index ee8f9c86..1c560ff 100644 --- a/third_party/WebKit/Source/core/css/BUILD.gn +++ b/third_party/WebKit/Source/core/css/BUILD.gn
@@ -347,6 +347,7 @@ "properties/CSSPropertyAPIBorderRadius.cpp", "properties/CSSPropertyAPICaretColor.cpp", "properties/CSSPropertyAPIClip.cpp", + "properties/CSSPropertyAPIClipPath.cpp", "properties/CSSPropertyAPIColumnGap.cpp", "properties/CSSPropertyAPIContain.cpp", "properties/CSSPropertyAPIContent.cpp", @@ -361,6 +362,7 @@ "properties/CSSPropertyAPIOffsetPosition.cpp", "properties/CSSPropertyAPIOutlineColor.cpp", "properties/CSSPropertyAPIOutlineOffset.cpp", + "properties/CSSPropertyAPIPadding.cpp", "properties/CSSPropertyAPIPage.cpp", "properties/CSSPropertyAPIPaintOrder.cpp", "properties/CSSPropertyAPIPaintStroke.cpp", @@ -392,6 +394,8 @@ "properties/CSSPropertyAPIZoom.cpp", "properties/CSSPropertyAlignmentUtils.cpp", "properties/CSSPropertyAlignmentUtils.h", + "properties/CSSPropertyColumnUtils.cpp", + "properties/CSSPropertyColumnUtils.h", "properties/CSSPropertyDescriptor.h", "properties/CSSPropertyLengthUtils.cpp", "properties/CSSPropertyLengthUtils.h",
diff --git a/third_party/WebKit/Source/core/css/CSSPrimitiveValueMappings.h b/third_party/WebKit/Source/core/css/CSSPrimitiveValueMappings.h index 6f43e93..766cc4f 100644 --- a/third_party/WebKit/Source/core/css/CSSPrimitiveValueMappings.h +++ b/third_party/WebKit/Source/core/css/CSSPrimitiveValueMappings.h
@@ -1002,112 +1002,112 @@ inline CSSIdentifierValue::CSSIdentifierValue(ECursor e) : CSSValue(IdentifierClass) { switch (e) { - case ECursor::Auto: + case ECursor::kAuto: m_valueID = CSSValueAuto; break; - case ECursor::Cross: + case ECursor::kCrosshair: m_valueID = CSSValueCrosshair; break; - case ECursor::Default: + case ECursor::kDefault: m_valueID = CSSValueDefault; break; - case ECursor::Pointer: + case ECursor::kPointer: m_valueID = CSSValuePointer; break; - case ECursor::Move: + case ECursor::kMove: m_valueID = CSSValueMove; break; - case ECursor::Cell: + case ECursor::kCell: m_valueID = CSSValueCell; break; - case ECursor::VerticalText: + case ECursor::kVerticalText: m_valueID = CSSValueVerticalText; break; - case ECursor::ContextMenu: + case ECursor::kContextMenu: m_valueID = CSSValueContextMenu; break; - case ECursor::Alias: + case ECursor::kAlias: m_valueID = CSSValueAlias; break; - case ECursor::Copy: + case ECursor::kCopy: m_valueID = CSSValueCopy; break; - case ECursor::None: + case ECursor::kNone: m_valueID = CSSValueNone; break; - case ECursor::Progress: + case ECursor::kProgress: m_valueID = CSSValueProgress; break; - case ECursor::NoDrop: + case ECursor::kNoDrop: m_valueID = CSSValueNoDrop; break; - case ECursor::NotAllowed: + case ECursor::kNotAllowed: m_valueID = CSSValueNotAllowed; break; - case ECursor::ZoomIn: + case ECursor::kZoomIn: m_valueID = CSSValueZoomIn; break; - case ECursor::ZoomOut: + case ECursor::kZoomOut: m_valueID = CSSValueZoomOut; break; - case ECursor::EResize: + case ECursor::kEResize: m_valueID = CSSValueEResize; break; - case ECursor::NeResize: + case ECursor::kNeResize: m_valueID = CSSValueNeResize; break; - case ECursor::NwResize: + case ECursor::kNwResize: m_valueID = CSSValueNwResize; break; - case ECursor::NResize: + case ECursor::kNResize: m_valueID = CSSValueNResize; break; - case ECursor::SeResize: + case ECursor::kSeResize: m_valueID = CSSValueSeResize; break; - case ECursor::SwResize: + case ECursor::kSwResize: m_valueID = CSSValueSwResize; break; - case ECursor::SResize: + case ECursor::kSResize: m_valueID = CSSValueSResize; break; - case ECursor::WResize: + case ECursor::kWResize: m_valueID = CSSValueWResize; break; - case ECursor::EwResize: + case ECursor::kEwResize: m_valueID = CSSValueEwResize; break; - case ECursor::NsResize: + case ECursor::kNsResize: m_valueID = CSSValueNsResize; break; - case ECursor::NeswResize: + case ECursor::kNeswResize: m_valueID = CSSValueNeswResize; break; - case ECursor::NwseResize: + case ECursor::kNwseResize: m_valueID = CSSValueNwseResize; break; - case ECursor::ColResize: + case ECursor::kColResize: m_valueID = CSSValueColResize; break; - case ECursor::RowResize: + case ECursor::kRowResize: m_valueID = CSSValueRowResize; break; - case ECursor::Text: + case ECursor::kText: m_valueID = CSSValueText; break; - case ECursor::Wait: + case ECursor::kWait: m_valueID = CSSValueWait; break; - case ECursor::Help: + case ECursor::kHelp: m_valueID = CSSValueHelp; break; - case ECursor::AllScroll: + case ECursor::kAllScroll: m_valueID = CSSValueAllScroll; break; - case ECursor::WebkitGrab: + case ECursor::kWebkitGrab: m_valueID = CSSValueWebkitGrab; break; - case ECursor::WebkitGrabbing: + case ECursor::kWebkitGrabbing: m_valueID = CSSValueWebkitGrabbing; break; } @@ -1117,82 +1117,82 @@ inline ECursor CSSIdentifierValue::convertTo() const { switch (m_valueID) { case CSSValueAuto: - return ECursor::Auto; + return ECursor::kAuto; case CSSValueCrosshair: - return ECursor::Cross; + return ECursor::kCrosshair; case CSSValueDefault: - return ECursor::Default; + return ECursor::kDefault; case CSSValuePointer: - return ECursor::Pointer; + return ECursor::kPointer; case CSSValueMove: - return ECursor::Move; + return ECursor::kMove; case CSSValueCell: - return ECursor::Cell; + return ECursor::kCell; case CSSValueVerticalText: - return ECursor::VerticalText; + return ECursor::kVerticalText; case CSSValueContextMenu: - return ECursor::ContextMenu; + return ECursor::kContextMenu; case CSSValueAlias: - return ECursor::Alias; + return ECursor::kAlias; case CSSValueCopy: - return ECursor::Copy; + return ECursor::kCopy; case CSSValueNone: - return ECursor::None; + return ECursor::kNone; case CSSValueProgress: - return ECursor::Progress; + return ECursor::kProgress; case CSSValueNoDrop: - return ECursor::NoDrop; + return ECursor::kNoDrop; case CSSValueNotAllowed: - return ECursor::NotAllowed; + return ECursor::kNotAllowed; case CSSValueZoomIn: case CSSValueWebkitZoomIn: - return ECursor::ZoomIn; + return ECursor::kZoomIn; case CSSValueZoomOut: case CSSValueWebkitZoomOut: - return ECursor::ZoomOut; + return ECursor::kZoomOut; case CSSValueEResize: - return ECursor::EResize; + return ECursor::kEResize; case CSSValueNeResize: - return ECursor::NeResize; + return ECursor::kNeResize; case CSSValueNwResize: - return ECursor::NwResize; + return ECursor::kNwResize; case CSSValueNResize: - return ECursor::NResize; + return ECursor::kNResize; case CSSValueSeResize: - return ECursor::SeResize; + return ECursor::kSeResize; case CSSValueSwResize: - return ECursor::SwResize; + return ECursor::kSwResize; case CSSValueSResize: - return ECursor::SResize; + return ECursor::kSResize; case CSSValueWResize: - return ECursor::WResize; + return ECursor::kWResize; case CSSValueEwResize: - return ECursor::EwResize; + return ECursor::kEwResize; case CSSValueNsResize: - return ECursor::NsResize; + return ECursor::kNsResize; case CSSValueNeswResize: - return ECursor::NeswResize; + return ECursor::kNeswResize; case CSSValueNwseResize: - return ECursor::NwseResize; + return ECursor::kNwseResize; case CSSValueColResize: - return ECursor::ColResize; + return ECursor::kColResize; case CSSValueRowResize: - return ECursor::RowResize; + return ECursor::kRowResize; case CSSValueText: - return ECursor::Text; + return ECursor::kText; case CSSValueWait: - return ECursor::Wait; + return ECursor::kWait; case CSSValueHelp: - return ECursor::Help; + return ECursor::kHelp; case CSSValueAllScroll: - return ECursor::AllScroll; + return ECursor::kAllScroll; case CSSValueWebkitGrab: - return ECursor::WebkitGrab; + return ECursor::kWebkitGrab; case CSSValueWebkitGrabbing: - return ECursor::WebkitGrabbing; + return ECursor::kWebkitGrabbing; default: NOTREACHED(); - return ECursor::Auto; + return ECursor::kAuto; } }
diff --git a/third_party/WebKit/Source/core/css/CSSProperties.in b/third_party/WebKit/Source/core/css/CSSProperties.in index 69d78b6c..16ff08e 100644 --- a/third_party/WebKit/Source/core/css/CSSProperties.in +++ b/third_party/WebKit/Source/core/css/CSSProperties.in
@@ -240,7 +240,7 @@ caret-color interpolable, inherited, custom_all, api_class clear clip interpolable, converter=convertClip, custom_all, api_class -clip-path interpolable, converter=convertClipPath +clip-path interpolable, converter=convertClipPath, api_class clip-rule inherited, svg, type_name=WindRule color-interpolation inherited, svg color-interpolation-filters inherited, svg, type_name=EColorInterpolation @@ -333,10 +333,10 @@ overflow-wrap inherited overflow-x type_name=EOverflow overflow-y type_name=EOverflow -padding-bottom interpolable, initial=initialPadding, converter=convertLength -padding-left interpolable, initial=initialPadding, converter=convertLength -padding-right interpolable, initial=initialPadding, converter=convertLength -padding-top interpolable, initial=initialPadding, converter=convertLength +padding-bottom interpolable, initial=initialPadding, converter=convertLength, api_class=CSSPropertyAPIPadding +padding-left interpolable, initial=initialPadding, converter=convertLength, api_class=CSSPropertyAPIPadding +padding-right interpolable, initial=initialPadding, converter=convertLength, api_class=CSSPropertyAPIPadding +padding-top interpolable, initial=initialPadding, converter=convertLength, api_class=CSSPropertyAPIPadding paint-order inherited, svg, converter=convertPaintOrder, api_class perspective interpolable, converter=convertPerspective perspective-origin interpolable, converter=convertPosition
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp index 5e523cc8..2810248 100644 --- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp +++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
@@ -42,6 +42,7 @@ #include "core/css/parser/CSSVariableParser.h" #include "core/css/parser/FontVariantLigaturesParser.h" #include "core/css/properties/CSSPropertyAlignmentUtils.h" +#include "core/css/properties/CSSPropertyColumnUtils.h" #include "core/css/properties/CSSPropertyDescriptor.h" #include "core/css/properties/CSSPropertyLengthUtils.h" #include "core/css/properties/CSSPropertyShapeUtils.h" @@ -639,25 +640,6 @@ return consumeString(range); } -static CSSValue* consumeColumnWidth(CSSParserTokenRange& range) { - if (range.peek().id() == CSSValueAuto) - return consumeIdent(range); - // Always parse lengths in strict mode here, since it would be ambiguous - // otherwise when used in the 'columns' shorthand property. - CSSPrimitiveValue* columnWidth = - consumeLength(range, HTMLStandardMode, ValueRangeNonNegative); - if (!columnWidth || - (!columnWidth->isCalculated() && columnWidth->getDoubleValue() == 0)) - return nullptr; - return columnWidth; -} - -static CSSValue* consumeColumnCount(CSSParserTokenRange& range) { - if (range.peek().id() == CSSValueAuto) - return consumeIdent(range); - return consumePositiveInteger(range); -} - static CSSValue* consumeColumnSpan(CSSParserTokenRange& range) { return consumeIdent<CSSValueAll, CSSValueNone>(range); } @@ -1438,15 +1420,6 @@ return nullptr; } -static CSSValue* consumeClipPath(CSSParserTokenRange& range, - const CSSParserContext* context) { - if (range.peek().id() == CSSValueNone) - return consumeIdent(range); - if (CSSURIValue* url = consumeUrl(range, context)) - return url; - return CSSPropertyShapeUtils::consumeBasicShape(range, context); -} - static CSSValue* consumeContentDistributionOverflowPosition( CSSParserTokenRange& range) { if (identMatches<CSSValueNormal, CSSValueBaseline, CSSValueLastBaseline>( @@ -2395,13 +2368,6 @@ case CSSPropertyWebkitMarginAfter: return consumeMarginOrOffset(m_range, m_context->mode(), UnitlessQuirk::Forbid); - case CSSPropertyPaddingTop: - case CSSPropertyPaddingRight: - case CSSPropertyPaddingBottom: - case CSSPropertyPaddingLeft: - return consumeLengthOrPercent(m_range, m_context->mode(), - ValueRangeNonNegative, - UnitlessQuirk::Allow); case CSSPropertyTouchAction: return consumeTouchAction(m_range); case CSSPropertyScrollSnapDestination: @@ -2415,9 +2381,9 @@ case CSSPropertyWebkitLocale: return consumeLocale(m_range); case CSSPropertyColumnWidth: - return consumeColumnWidth(m_range); + return CSSPropertyColumnUtils::consumeColumnWidth(m_range); case CSSPropertyColumnCount: - return consumeColumnCount(m_range); + return CSSPropertyColumnUtils::consumeColumnCount(m_range); case CSSPropertyColumnSpan: return consumeColumnSpan(m_range); case CSSPropertyAnimationDelay: @@ -2573,8 +2539,6 @@ return consumeScrollSnapPoints(m_range, m_context->mode()); case CSSPropertyOrder: return consumeInteger(m_range); - case CSSPropertyClipPath: - return consumeClipPath(m_range, m_context); case CSSPropertyJustifyContent: case CSSPropertyAlignContent: ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); @@ -3104,29 +3068,14 @@ } } -static bool consumeColumnWidthOrCount(CSSParserTokenRange& range, - CSSValue*& columnWidth, - CSSValue*& columnCount) { - if (range.peek().id() == CSSValueAuto) { - consumeIdent(range); - return true; - } - if (!columnWidth) { - columnWidth = consumeColumnWidth(range); - if (columnWidth) - return true; - } - if (!columnCount) - columnCount = consumeColumnCount(range); - return columnCount; -} - bool CSSPropertyParser::consumeColumns(bool important) { CSSValue* columnWidth = nullptr; CSSValue* columnCount = nullptr; - if (!consumeColumnWidthOrCount(m_range, columnWidth, columnCount)) + if (!CSSPropertyColumnUtils::consumeColumnWidthOrCount(m_range, columnWidth, + columnCount)) return false; - consumeColumnWidthOrCount(m_range, columnWidth, columnCount); + CSSPropertyColumnUtils::consumeColumnWidthOrCount(m_range, columnWidth, + columnCount); if (!m_range.atEnd()) return false; if (!columnWidth)
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClipPath.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClipPath.cpp new file mode 100644 index 0000000..e89bc22 --- /dev/null +++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClipPath.cpp
@@ -0,0 +1,23 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/css/properties/CSSPropertyAPIClipPath.h" + +#include "core/css/CSSURIValue.h" +#include "core/css/parser/CSSPropertyParserHelpers.h" +#include "core/css/properties/CSSPropertyShapeUtils.h" + +namespace blink { + +const CSSValue* CSSPropertyAPIClipPath::parseSingleValue( + CSSParserTokenRange& range, + const CSSParserContext* context) { + if (range.peek().id() == CSSValueNone) + return CSSPropertyParserHelpers::consumeIdent(range); + if (CSSURIValue* url = CSSPropertyParserHelpers::consumeUrl(range, context)) + return url; + return CSSPropertyShapeUtils::consumeBasicShape(range, context); +} + +} // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPadding.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPadding.cpp new file mode 100644 index 0000000..2acae08 --- /dev/null +++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIPadding.cpp
@@ -0,0 +1,19 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/css/properties/CSSPropertyAPIPadding.h" + +#include "core/css/parser/CSSParserContext.h" +#include "core/css/parser/CSSPropertyParserHelpers.h" + +namespace blink { + +const CSSValue* CSSPropertyAPIPadding::parseSingleValue( + CSSParserTokenRange& range, + const CSSParserContext* context) { + return consumeLengthOrPercent(range, context->mode(), ValueRangeNonNegative, + CSSPropertyParserHelpers::UnitlessQuirk::Allow); +} + +} // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyColumnUtils.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyColumnUtils.cpp new file mode 100644 index 0000000..bad20aa2 --- /dev/null +++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyColumnUtils.cpp
@@ -0,0 +1,52 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/css/properties/CSSPropertyColumnUtils.h" + +#include "core/css/CSSPrimitiveValue.h" +#include "core/css/parser/CSSParserTokenRange.h" +#include "core/css/parser/CSSPropertyParserHelpers.h" + +namespace blink { + +CSSValue* CSSPropertyColumnUtils::consumeColumnCount( + CSSParserTokenRange& range) { + if (range.peek().id() == CSSValueAuto) + return CSSPropertyParserHelpers::consumeIdent(range); + return CSSPropertyParserHelpers::consumePositiveInteger(range); +} + +CSSValue* CSSPropertyColumnUtils::consumeColumnWidth( + CSSParserTokenRange& range) { + if (range.peek().id() == CSSValueAuto) + return CSSPropertyParserHelpers::consumeIdent(range); + // Always parse lengths in strict mode here, since it would be ambiguous + // otherwise when used in the 'columns' shorthand property. + CSSPrimitiveValue* columnWidth = CSSPropertyParserHelpers::consumeLength( + range, HTMLStandardMode, ValueRangeNonNegative); + if (!columnWidth || + (!columnWidth->isCalculated() && columnWidth->getDoubleValue() == 0)) + return nullptr; + return columnWidth; +} + +bool CSSPropertyColumnUtils::consumeColumnWidthOrCount( + CSSParserTokenRange& range, + CSSValue*& columnWidth, + CSSValue*& columnCount) { + if (range.peek().id() == CSSValueAuto) { + CSSPropertyParserHelpers::consumeIdent(range); + return true; + } + if (!columnWidth) { + columnWidth = consumeColumnWidth(range); + if (columnWidth) + return true; + } + if (!columnCount) + columnCount = consumeColumnCount(range); + return columnCount; +} + +} // namespace blink
diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyColumnUtils.h b/third_party/WebKit/Source/core/css/properties/CSSPropertyColumnUtils.h new file mode 100644 index 0000000..bf67a9b --- /dev/null +++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyColumnUtils.h
@@ -0,0 +1,29 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CSSPropertyColumnUtils_h +#define CSSPropertyColumnUtils_h + +#include "wtf/Allocator.h" + +namespace blink { + +class CSSParserTokenRange; +class CSSValue; + +class CSSPropertyColumnUtils { + STATIC_ONLY(CSSPropertyColumnUtils); + + static CSSValue* consumeColumnCount(CSSParserTokenRange&); + + static CSSValue* consumeColumnWidth(CSSParserTokenRange&); + + static bool consumeColumnWidthOrCount(CSSParserTokenRange&, + CSSValue*&, + CSSValue*&); +}; + +} // namespace blink + +#endif // CSSPropertyColumnUtils_h
diff --git a/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp b/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp index 246dcc0..f9fdcd54 100644 --- a/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp +++ b/third_party/WebKit/Source/core/css/resolver/StyleBuilderCustom.cpp
@@ -213,7 +213,7 @@ const CSSValue& value) { state.style()->clearCursorList(); if (value.isValueList()) { - state.style()->setCursor(ECursor::Auto); + state.style()->setCursor(ECursor::kAuto); for (const auto& item : toCSSValueList(value)) { if (item->isCursorImageValue()) { const CSSCursorImageValue& cursor = toCSSCursorImageValue(*item);
diff --git a/third_party/WebKit/Source/core/dom/BUILD.gn b/third_party/WebKit/Source/core/dom/BUILD.gn index 48183ef2..d744cfc 100644 --- a/third_party/WebKit/Source/core/dom/BUILD.gn +++ b/third_party/WebKit/Source/core/dom/BUILD.gn
@@ -229,6 +229,15 @@ "RawDataDocumentParser.h", "RemoteSecurityContext.cpp", "RemoteSecurityContext.h", + "ResizeObservation.cpp", + "ResizeObservation.h", + "ResizeObserver.cpp", + "ResizeObserver.h", + "ResizeObserverCallback.h", + "ResizeObserverController.cpp", + "ResizeObserverController.h", + "ResizeObserverEntry.cpp", + "ResizeObserverEntry.h", "SandboxFlags.cpp", "SandboxFlags.h", "ScopedWindowFocusAllowedIndicator.h",
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp index 53d69df..49cb3d2 100644 --- a/third_party/WebKit/Source/core/dom/Document.cpp +++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -98,6 +98,7 @@ #include "core/dom/NodeWithIndex.h" #include "core/dom/NthIndexCache.h" #include "core/dom/ProcessingInstruction.h" +#include "core/dom/ResizeObserverController.h" #include "core/dom/ScriptRunner.h" #include "core/dom/ScriptedAnimationController.h" #include "core/dom/ScriptedIdleTaskController.h" @@ -201,7 +202,6 @@ #include "core/loader/NavigationScheduler.h" #include "core/loader/PrerendererClient.h" #include "core/loader/appcache/ApplicationCacheHost.h" -#include "core/observer/ResizeObserverController.h" #include "core/page/ChromeClient.h" #include "core/page/EventWithHitTestResults.h" #include "core/page/FocusController.h"
diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp index 75e7dc2..8e2e171 100644 --- a/third_party/WebKit/Source/core/dom/Element.cpp +++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -70,6 +70,7 @@ #include "core/dom/NodeComputedStyle.h" #include "core/dom/PresentationAttributeStyle.h" #include "core/dom/PseudoElement.h" +#include "core/dom/ResizeObservation.h" #include "core/dom/ScriptableDocumentParser.h" #include "core/dom/SelectorQuery.h" #include "core/dom/StyleChangeReason.h" @@ -121,7 +122,6 @@ #include "core/layout/api/LayoutBoxItem.h" #include "core/layout/api/LayoutViewItem.h" #include "core/loader/DocumentLoader.h" -#include "core/observer/ResizeObservation.h" #include "core/page/ChromeClient.h" #include "core/page/FocusController.h" #include "core/page/Page.h"
diff --git a/third_party/WebKit/Source/core/dom/ElementRareData.cpp b/third_party/WebKit/Source/core/dom/ElementRareData.cpp index 4f4445a..18c8f63 100644 --- a/third_party/WebKit/Source/core/dom/ElementRareData.cpp +++ b/third_party/WebKit/Source/core/dom/ElementRareData.cpp
@@ -32,8 +32,8 @@ #include "core/css/cssom/InlineStylePropertyMap.h" #include "core/dom/CompositorProxiedPropertySet.h" -#include "core/observer/ResizeObservation.h" -#include "core/observer/ResizeObserver.h" +#include "core/dom/ResizeObservation.h" +#include "core/dom/ResizeObserver.h" #include "core/style/ComputedStyle.h" namespace blink {
diff --git a/third_party/WebKit/Source/core/observer/ResizeObservation.cpp b/third_party/WebKit/Source/core/dom/ResizeObservation.cpp similarity index 95% rename from third_party/WebKit/Source/core/observer/ResizeObservation.cpp rename to third_party/WebKit/Source/core/dom/ResizeObservation.cpp index 81517bc..dfe56a2 100644 --- a/third_party/WebKit/Source/core/observer/ResizeObservation.cpp +++ b/third_party/WebKit/Source/core/dom/ResizeObservation.cpp
@@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/observer/ResizeObservation.h" +#include "core/dom/ResizeObservation.h" +#include "core/dom/ResizeObserver.h" #include "core/layout/LayoutBox.h" -#include "core/observer/ResizeObserver.h" #include "core/svg/SVGElement.h" #include "core/svg/SVGGraphicsElement.h"
diff --git a/third_party/WebKit/Source/core/observer/ResizeObservation.h b/third_party/WebKit/Source/core/dom/ResizeObservation.h similarity index 95% rename from third_party/WebKit/Source/core/observer/ResizeObservation.h rename to third_party/WebKit/Source/core/dom/ResizeObservation.h index c6f4c65..b9784f4 100644 --- a/third_party/WebKit/Source/core/observer/ResizeObservation.h +++ b/third_party/WebKit/Source/core/dom/ResizeObservation.h
@@ -5,7 +5,7 @@ #ifndef ResizeObservation_h #define ResizeObservation_h -#include "core/observer/ResizeObserverEntry.h" +#include "core/dom/ResizeObserverEntry.h" #include "platform/geometry/LayoutSize.h" #include "platform/heap/Handle.h"
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserver.cpp b/third_party/WebKit/Source/core/dom/ResizeObserver.cpp similarity index 93% rename from third_party/WebKit/Source/core/observer/ResizeObserver.cpp rename to third_party/WebKit/Source/core/dom/ResizeObserver.cpp index f64cd528..1fc0d31 100644 --- a/third_party/WebKit/Source/core/observer/ResizeObserver.cpp +++ b/third_party/WebKit/Source/core/dom/ResizeObserver.cpp
@@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/observer/ResizeObserver.h" +#include "core/dom/ResizeObserver.h" #include "core/dom/Element.h" +#include "core/dom/ResizeObservation.h" +#include "core/dom/ResizeObserverCallback.h" +#include "core/dom/ResizeObserverController.h" +#include "core/dom/ResizeObserverEntry.h" #include "core/frame/FrameView.h" -#include "core/observer/ResizeObservation.h" -#include "core/observer/ResizeObserverCallback.h" -#include "core/observer/ResizeObserverController.h" -#include "core/observer/ResizeObserverEntry.h" namespace blink {
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserver.h b/third_party/WebKit/Source/core/dom/ResizeObserver.h similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserver.h rename to third_party/WebKit/Source/core/dom/ResizeObserver.h
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserver.idl b/third_party/WebKit/Source/core/dom/ResizeObserver.idl similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserver.idl rename to third_party/WebKit/Source/core/dom/ResizeObserver.idl
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverCallback.h b/third_party/WebKit/Source/core/dom/ResizeObserverCallback.h similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserverCallback.h rename to third_party/WebKit/Source/core/dom/ResizeObserverCallback.h
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverCallback.idl b/third_party/WebKit/Source/core/dom/ResizeObserverCallback.idl similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserverCallback.idl rename to third_party/WebKit/Source/core/dom/ResizeObserverCallback.idl
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverController.cpp b/third_party/WebKit/Source/core/dom/ResizeObserverController.cpp similarity index 94% rename from third_party/WebKit/Source/core/observer/ResizeObserverController.cpp rename to third_party/WebKit/Source/core/dom/ResizeObserverController.cpp index 43337c3..685eb58 100644 --- a/third_party/WebKit/Source/core/observer/ResizeObserverController.cpp +++ b/third_party/WebKit/Source/core/dom/ResizeObserverController.cpp
@@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/observer/ResizeObserverController.h" +#include "core/dom/ResizeObserverController.h" -#include "core/observer/ResizeObserver.h" +#include "core/dom/ResizeObserver.h" namespace blink {
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverController.h b/third_party/WebKit/Source/core/dom/ResizeObserverController.h similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserverController.h rename to third_party/WebKit/Source/core/dom/ResizeObserverController.h
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverEntry.cpp b/third_party/WebKit/Source/core/dom/ResizeObserverEntry.cpp similarity index 87% rename from third_party/WebKit/Source/core/observer/ResizeObserverEntry.cpp rename to third_party/WebKit/Source/core/dom/ResizeObserverEntry.cpp index 7f038460..b6a2c27 100644 --- a/third_party/WebKit/Source/core/observer/ResizeObserverEntry.cpp +++ b/third_party/WebKit/Source/core/dom/ResizeObserverEntry.cpp
@@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/observer/ResizeObserverEntry.h" +#include "core/dom/ResizeObserverEntry.h" #include "core/dom/ClientRect.h" #include "core/dom/Element.h" -#include "core/observer/ResizeObservation.h" +#include "core/dom/ResizeObservation.h" namespace blink {
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverEntry.h b/third_party/WebKit/Source/core/dom/ResizeObserverEntry.h similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserverEntry.h rename to third_party/WebKit/Source/core/dom/ResizeObserverEntry.h
diff --git a/third_party/WebKit/Source/core/observer/ResizeObserverEntry.idl b/third_party/WebKit/Source/core/dom/ResizeObserverEntry.idl similarity index 100% rename from third_party/WebKit/Source/core/observer/ResizeObserverEntry.idl rename to third_party/WebKit/Source/core/dom/ResizeObserverEntry.idl
diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp index ad91f9d..f4470c8 100644 --- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp +++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
@@ -454,10 +454,12 @@ return true; LocalFrame* frame = contextDocument->frame(); + if (!frame) + return true; const ContentSecurityPolicy* csp = elementDocument->contentSecurityPolicy(); bool shouldBypassMainWorldCSP = - (frame && frame->script().shouldBypassMainWorldCSP()) || + (frame->script().shouldBypassMainWorldCSP()) || csp->allowScriptWithHash(sourceCode.source(), ContentSecurityPolicy::InlineType::Block); @@ -510,11 +512,6 @@ } } - // FIXME: Can this be moved earlier in the function? - // Why are we ever attempting to execute scripts without a frame? - if (!frame) - return true; - AccessControlStatus accessControlStatus = NotSharableCrossOrigin; if (!m_isExternalScript) { accessControlStatus = SharableCrossOrigin;
diff --git a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp index c7f578b3..f1ea1ac8 100644 --- a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp +++ b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.cpp
@@ -31,6 +31,7 @@ case TaskType::DatabaseAccess: case TaskType::Presentation: case TaskType::Sensor: + case TaskType::PerformanceTimeline: case TaskType::Timer: case TaskType::UnspecedTimer: case TaskType::MiscPlatformAPI:
diff --git a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h index 37710d0..933c580 100644 --- a/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h +++ b/third_party/WebKit/Source/core/dom/TaskRunnerHelper.h
@@ -95,6 +95,9 @@ // This task source is used for all tasks in the Sensor API spec. Sensor, + // https://w3c.github.io/performance-timeline/#performance-timeline + PerformanceTimeline, + // Use MiscPlatformAPI for a task that is defined in the spec but is not yet // associated with any specific task runner in the spec. MiscPlatformAPI is // not encouraged for stable and matured APIs. The spec should define the task
diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp index b3c41e3..4e5fc3c 100644 --- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp +++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp
@@ -496,6 +496,7 @@ // really do the same, since we don't support discontiguous selection. Further // discussions at // <https://code.google.com/p/chromium/issues/detail?id=353069>. + UseCounter::count(frame(), UseCounter::SelectionAddRangeIntersect); Range* start = originalRange->compareBoundaryPoints( Range::kStartToStart, newRange, ASSERT_NO_EXCEPTION) < 0
diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp index 19d93411..9b01ca9f 100644 --- a/third_party/WebKit/Source/core/frame/FrameView.cpp +++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
@@ -37,6 +37,7 @@ #include "core/dom/IntersectionObserverCallback.h" #include "core/dom/IntersectionObserverController.h" #include "core/dom/IntersectionObserverInit.h" +#include "core/dom/ResizeObserverController.h" #include "core/dom/StyleChangeReason.h" #include "core/dom/TaskRunnerHelper.h" #include "core/editing/EditingUtilities.h" @@ -85,7 +86,6 @@ #include "core/loader/DocumentLoader.h" #include "core/loader/FrameLoader.h" #include "core/loader/FrameLoaderClient.h" -#include "core/observer/ResizeObserverController.h" #include "core/page/AutoscrollController.h" #include "core/page/ChromeClient.h" #include "core/page/FocusController.h"
diff --git a/third_party/WebKit/Source/core/frame/UseCounter.h b/third_party/WebKit/Source/core/frame/UseCounter.h index 1d02024..a5140028 100644 --- a/third_party/WebKit/Source/core/frame/UseCounter.h +++ b/third_party/WebKit/Source/core/frame/UseCounter.h
@@ -1443,6 +1443,7 @@ HTMLTableCellElementColspan = 1783, HTMLTableCellElementColspanGreaterThan1000 = 1784, HTMLTableCellElementColspanGreaterThan8190 = 1785, + SelectionAddRangeIntersect = 1786, // Add new features immediately above this line. Don't change assigned // numbers of any item, and don't reuse removed slots.
diff --git a/third_party/WebKit/Source/core/input/EventHandler.cpp b/third_party/WebKit/Source/core/input/EventHandler.cpp index e7b31f2..31405d7 100644 --- a/third_party/WebKit/Source/core/input/EventHandler.cpp +++ b/third_party/WebKit/Source/core/input/EventHandler.cpp
@@ -447,82 +447,82 @@ } } - switch (style ? style->cursor() : ECursor::Auto) { - case ECursor::Auto: { + switch (style ? style->cursor() : ECursor::kAuto) { + case ECursor::kAuto: { bool horizontalText = !style || style->isHorizontalWritingMode(); const Cursor& iBeam = horizontalText ? iBeamCursor() : verticalTextCursor(); return selectAutoCursor(result, node, iBeam); } - case ECursor::Cross: + case ECursor::kCrosshair: return crossCursor(); - case ECursor::Pointer: + case ECursor::kPointer: return handCursor(); - case ECursor::Move: + case ECursor::kMove: return moveCursor(); - case ECursor::AllScroll: + case ECursor::kAllScroll: return moveCursor(); - case ECursor::EResize: + case ECursor::kEResize: return eastResizeCursor(); - case ECursor::WResize: + case ECursor::kWResize: return westResizeCursor(); - case ECursor::NResize: + case ECursor::kNResize: return northResizeCursor(); - case ECursor::SResize: + case ECursor::kSResize: return southResizeCursor(); - case ECursor::NeResize: + case ECursor::kNeResize: return northEastResizeCursor(); - case ECursor::SwResize: + case ECursor::kSwResize: return southWestResizeCursor(); - case ECursor::NwResize: + case ECursor::kNwResize: return northWestResizeCursor(); - case ECursor::SeResize: + case ECursor::kSeResize: return southEastResizeCursor(); - case ECursor::NsResize: + case ECursor::kNsResize: return northSouthResizeCursor(); - case ECursor::EwResize: + case ECursor::kEwResize: return eastWestResizeCursor(); - case ECursor::NeswResize: + case ECursor::kNeswResize: return northEastSouthWestResizeCursor(); - case ECursor::NwseResize: + case ECursor::kNwseResize: return northWestSouthEastResizeCursor(); - case ECursor::ColResize: + case ECursor::kColResize: return columnResizeCursor(); - case ECursor::RowResize: + case ECursor::kRowResize: return rowResizeCursor(); - case ECursor::Text: + case ECursor::kText: return iBeamCursor(); - case ECursor::Wait: + case ECursor::kWait: return waitCursor(); - case ECursor::Help: + case ECursor::kHelp: return helpCursor(); - case ECursor::VerticalText: + case ECursor::kVerticalText: return verticalTextCursor(); - case ECursor::Cell: + case ECursor::kCell: return cellCursor(); - case ECursor::ContextMenu: + case ECursor::kContextMenu: return contextMenuCursor(); - case ECursor::Progress: + case ECursor::kProgress: return progressCursor(); - case ECursor::NoDrop: + case ECursor::kNoDrop: return noDropCursor(); - case ECursor::Alias: + case ECursor::kAlias: return aliasCursor(); - case ECursor::Copy: + case ECursor::kCopy: return copyCursor(); - case ECursor::None: + case ECursor::kNone: return noneCursor(); - case ECursor::NotAllowed: + case ECursor::kNotAllowed: return notAllowedCursor(); - case ECursor::Default: + case ECursor::kDefault: return pointerCursor(); - case ECursor::ZoomIn: + case ECursor::kZoomIn: return zoomInCursor(); - case ECursor::ZoomOut: + case ECursor::kZoomOut: return zoomOutCursor(); - case ECursor::WebkitGrab: + case ECursor::kWebkitGrab: return grabCursor(); - case ECursor::WebkitGrabbing: + case ECursor::kWebkitGrabbing: return grabbingCursor(); } return pointerCursor();
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc index f08222e7..0b98fa07 100644 --- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc +++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm_test.cc
@@ -12,6 +12,7 @@ #include "core/layout/ng/ng_physical_box_fragment.h" #include "core/layout/ng/ng_physical_fragment.h" #include "core/layout/ng/ng_units.h" +#include "core/layout/LayoutTestHelper.h" #include "core/style/ComputedStyle.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,9 +32,19 @@ .ToConstraintSpace(); } -class NGBlockLayoutAlgorithmTest : public ::testing::Test { +typedef bool TestParamLayoutNG; +class NGBlockLayoutAlgorithmTest + : public ::testing::WithParamInterface<TestParamLayoutNG>, + public RenderingTest { + public: + NGBlockLayoutAlgorithmTest() {} + protected: - void SetUp() override { style_ = ComputedStyle::create(); } + void SetUp() override { + style_ = ComputedStyle::create(); + RenderingTest::SetUp(); + enableCompositing(); + } NGPhysicalBoxFragment* RunBlockLayoutAlgorithm(NGConstraintSpace* space, NGBlockNode* first_child) {
diff --git a/third_party/WebKit/Source/core/observer/BUILD.gn b/third_party/WebKit/Source/core/observer/BUILD.gn deleted file mode 100644 index cdaef4e9..0000000 --- a/third_party/WebKit/Source/core/observer/BUILD.gn +++ /dev/null
@@ -1,24 +0,0 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//third_party/WebKit/Source/core/core.gni") - -blink_core_sources("observer") { - sources = [ - "ResizeObservation.cpp", - "ResizeObservation.h", - "ResizeObserver.cpp", - "ResizeObserver.h", - "ResizeObserverCallback.h", - "ResizeObserverController.cpp", - "ResizeObserverController.h", - "ResizeObserverEntry.cpp", - "ResizeObserverEntry.h", - ] - - configs += [ - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - "//build/config/compiler:no_size_t_to_int_warning", - ] -}
diff --git a/third_party/WebKit/Source/core/style/ComputedStyle.h b/third_party/WebKit/Source/core/style/ComputedStyle.h index 4108cf3..f8b0e9a 100644 --- a/third_party/WebKit/Source/core/style/ComputedStyle.h +++ b/third_party/WebKit/Source/core/style/ComputedStyle.h
@@ -1993,7 +1993,7 @@ void setVerticalBorderSpacing(short); // cursor - static ECursor initialCursor() { return ECursor::Auto; } + static ECursor initialCursor() { return ECursor::kAuto; } ECursor cursor() const { return static_cast<ECursor>(m_inheritedData.m_cursorStyle); }
diff --git a/third_party/WebKit/Source/core/style/ComputedStyleConstants.h b/third_party/WebKit/Source/core/style/ComputedStyleConstants.h index 4f59d7e..6b70937 100644 --- a/third_party/WebKit/Source/core/style/ComputedStyleConstants.h +++ b/third_party/WebKit/Source/core/style/ComputedStyleConstants.h
@@ -342,42 +342,42 @@ }; enum class ECursor : unsigned { - Auto, - Cross, - Default, - Pointer, - Move, - VerticalText, - Cell, - ContextMenu, - Alias, - Progress, - NoDrop, - NotAllowed, - ZoomIn, - ZoomOut, - EResize, - NeResize, - NwResize, - NResize, - SeResize, - SwResize, - SResize, - WResize, - EwResize, - NsResize, - NeswResize, - NwseResize, - ColResize, - RowResize, - Text, - Wait, - Help, - AllScroll, - WebkitGrab, - WebkitGrabbing, - Copy, - None + kAuto, + kCrosshair, + kDefault, + kPointer, + kMove, + kVerticalText, + kCell, + kContextMenu, + kAlias, + kProgress, + kNoDrop, + kNotAllowed, + kZoomIn, + kZoomOut, + kEResize, + kNeResize, + kNwResize, + kNResize, + kSeResize, + kSwResize, + kSResize, + kWResize, + kEwResize, + kNsResize, + kNeswResize, + kNwseResize, + kColResize, + kRowResize, + kText, + kWait, + kHelp, + kAllScroll, + kWebkitGrab, + kWebkitGrabbing, + kCopy, + kNone }; enum class EDisplay : unsigned {
diff --git a/third_party/WebKit/Source/core/timing/Performance.cpp b/third_party/WebKit/Source/core/timing/Performance.cpp index be8ca98..1268af7 100644 --- a/third_party/WebKit/Source/core/timing/Performance.cpp +++ b/third_party/WebKit/Source/core/timing/Performance.cpp
@@ -35,6 +35,7 @@ #include "bindings/core/v8/V8ObjectBuilder.h" #include "core/dom/Document.h" #include "core/dom/QualifiedName.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/frame/DOMWindow.h" #include "core/frame/LocalFrame.h" #include "core/frame/UseCounter.h" @@ -48,7 +49,7 @@ static const char kUnknownAttribution[] = "unknown"; static const char kAmbiguousAttribution[] = "multiple-contexts"; static const char kSameOriginAttribution[] = "same-origin"; -static const char kSameOriginSelfAttribution[] = "same-origin-self"; +static const char kSameOriginSelfAttribution[] = "self"; static const char kSameOriginAncestorAttribution[] = "same-origin-ancestor"; static const char kSameOriginDescendantAttribution[] = "same-origin-descendant"; static const char kCrossOriginAncestorAttribution[] = "cross-origin-ancestor"; @@ -100,7 +101,9 @@ } Performance::Performance(LocalFrame* frame) - : PerformanceBase(toTimeOrigin(frame)), + : PerformanceBase( + toTimeOrigin(frame), + TaskRunnerHelper::get(TaskType::PerformanceTimeline, frame)), ContextLifecycleObserver(frame ? frame->document() : nullptr) {} Performance::~Performance() {
diff --git a/third_party/WebKit/Source/core/timing/PerformanceBase.cpp b/third_party/WebKit/Source/core/timing/PerformanceBase.cpp index ba4eb8f..56b483ab 100644 --- a/third_party/WebKit/Source/core/timing/PerformanceBase.cpp +++ b/third_party/WebKit/Source/core/timing/PerformanceBase.cpp
@@ -66,13 +66,15 @@ static const size_t defaultResourceTimingBufferSize = 150; static const size_t defaultFrameTimingBufferSize = 150; -PerformanceBase::PerformanceBase(double timeOrigin) +PerformanceBase::PerformanceBase(double timeOrigin, + RefPtr<WebTaskRunner> taskRunner) : m_frameTimingBufferSize(defaultFrameTimingBufferSize), m_resourceTimingBufferSize(defaultResourceTimingBufferSize), m_userTiming(nullptr), m_timeOrigin(timeOrigin), m_observerFilterOptions(PerformanceEntry::Invalid), m_deliverObservationsTimer( + std::move(taskRunner), this, &PerformanceBase::deliverObservationsTimerFired) {}
diff --git a/third_party/WebKit/Source/core/timing/PerformanceBase.h b/third_party/WebKit/Source/core/timing/PerformanceBase.h index d4d9f69..ae34e98 100644 --- a/third_party/WebKit/Source/core/timing/PerformanceBase.h +++ b/third_party/WebKit/Source/core/timing/PerformanceBase.h
@@ -155,7 +155,7 @@ void addPaintTiming(PerformancePaintTiming::PaintType, double startTime); protected: - explicit PerformanceBase(double timeOrigin); + explicit PerformanceBase(double timeOrigin, RefPtr<WebTaskRunner>); bool isResourceTimingBufferFull(); void addResourceTimingBuffer(PerformanceEntry&); @@ -181,7 +181,7 @@ PerformanceObservers m_observers; PerformanceObservers m_activeObservers; PerformanceObservers m_suspendedObservers; - Timer<PerformanceBase> m_deliverObservationsTimer; + TaskRunnerTimer<PerformanceBase> m_deliverObservationsTimer; }; } // namespace blink
diff --git a/third_party/WebKit/Source/core/timing/PerformanceBaseTest.cpp b/third_party/WebKit/Source/core/timing/PerformanceBaseTest.cpp index 78ac999..2cbe0464 100644 --- a/third_party/WebKit/Source/core/timing/PerformanceBaseTest.cpp +++ b/third_party/WebKit/Source/core/timing/PerformanceBaseTest.cpp
@@ -6,6 +6,7 @@ #include "bindings/core/v8/PerformanceObserverCallback.h" #include "bindings/core/v8/V8BindingForTesting.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/testing/DummyPageHolder.h" #include "core/testing/NullExecutionContext.h" #include "core/timing/PerformanceBase.h" @@ -19,7 +20,11 @@ class TestPerformanceBase : public PerformanceBase { public: - TestPerformanceBase() : PerformanceBase(0) {} + explicit TestPerformanceBase(ScriptState* scriptState) + : PerformanceBase( + 0, + TaskRunnerHelper::get(TaskType::PerformanceTimeline, scriptState)) { + } ~TestPerformanceBase() {} ExecutionContext* getExecutionContext() const override { return nullptr; } @@ -40,7 +45,7 @@ void initialize(ScriptState* scriptState) { v8::Local<v8::Function> callback = v8::Function::New(scriptState->context(), nullptr).ToLocalChecked(); - m_base = new TestPerformanceBase(); + m_base = new TestPerformanceBase(scriptState); m_cb = PerformanceObserverCallback::create(scriptState, callback); m_observer = PerformanceObserver::create(scriptState->getExecutionContext(), m_base, m_cb);
diff --git a/third_party/WebKit/Source/core/timing/PerformanceLongTaskTiming.cpp b/third_party/WebKit/Source/core/timing/PerformanceLongTaskTiming.cpp index 63e1658..ab0d08e 100644 --- a/third_party/WebKit/Source/core/timing/PerformanceLongTaskTiming.cpp +++ b/third_party/WebKit/Source/core/timing/PerformanceLongTaskTiming.cpp
@@ -39,9 +39,10 @@ "longtask", clampToMillisecond(startTime), clampToMillisecond(endTime)) { - // Only one possible name ("frame") currently. + // Only one possible task type exists currently: "script" + // Only one possible container type exists currently: "iframe" TaskAttributionTiming* attributionEntry = TaskAttributionTiming::create( - "frame", culpritFrameSrc, culpritFrameId, culpritFrameName); + "script", "iframe", culpritFrameSrc, culpritFrameId, culpritFrameName); m_attribution.push_back(*attributionEntry); }
diff --git a/third_party/WebKit/Source/core/timing/PerformanceObserverTest.cpp b/third_party/WebKit/Source/core/timing/PerformanceObserverTest.cpp index 8d6a66d..f63c8b28 100644 --- a/third_party/WebKit/Source/core/timing/PerformanceObserverTest.cpp +++ b/third_party/WebKit/Source/core/timing/PerformanceObserverTest.cpp
@@ -6,6 +6,7 @@ #include "bindings/core/v8/PerformanceObserverCallback.h" #include "bindings/core/v8/V8BindingForTesting.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/timing/Performance.h" #include "core/timing/PerformanceBase.h" #include "core/timing/PerformanceMark.h" @@ -16,7 +17,11 @@ class MockPerformanceBase : public PerformanceBase { public: - MockPerformanceBase() : PerformanceBase(0) {} + explicit MockPerformanceBase(ScriptState* scriptState) + : PerformanceBase( + 0, + TaskRunnerHelper::get(TaskType::PerformanceTimeline, scriptState)) { + } ~MockPerformanceBase() {} ExecutionContext* getExecutionContext() const override { return nullptr; } @@ -27,7 +32,7 @@ void initialize(ScriptState* scriptState) { v8::Local<v8::Function> callback = v8::Function::New(scriptState->context(), nullptr).ToLocalChecked(); - m_base = new MockPerformanceBase(); + m_base = new MockPerformanceBase(scriptState); m_cb = PerformanceObserverCallback::create(scriptState, callback); m_observer = PerformanceObserver::create(scriptState->getExecutionContext(), m_base, m_cb);
diff --git a/third_party/WebKit/Source/core/timing/PerformanceTest.cpp b/third_party/WebKit/Source/core/timing/PerformanceTest.cpp index 9d6d960a..893b97ec 100644 --- a/third_party/WebKit/Source/core/timing/PerformanceTest.cpp +++ b/third_party/WebKit/Source/core/timing/PerformanceTest.cpp
@@ -81,8 +81,7 @@ EXPECT_EQ("unknown", sanitizedAttribution(nullptr, false, frame())); // Attribute for same context (and same origin). - EXPECT_EQ("same-origin-self", - sanitizedAttribution(document(), false, frame())); + EXPECT_EQ("self", sanitizedAttribution(document(), false, frame())); // Unable to attribute, when multiple script execution contents are involved. EXPECT_EQ("multiple-contexts",
diff --git a/third_party/WebKit/Source/core/timing/TaskAttributionTiming.cpp b/third_party/WebKit/Source/core/timing/TaskAttributionTiming.cpp index 9f4ab74b3..1edcf83 100644 --- a/third_party/WebKit/Source/core/timing/TaskAttributionTiming.cpp +++ b/third_party/WebKit/Source/core/timing/TaskAttributionTiming.cpp
@@ -9,26 +9,32 @@ namespace blink { TaskAttributionTiming::TaskAttributionTiming(String name, - String frameSrc, - String frameId, - String frameName) + String containerType, + String containerSrc, + String containerId, + String containerName) : PerformanceEntry(name, "taskattribution", 0.0, 0.0), - m_frameSrc(frameSrc), - m_frameId(frameId), - m_frameName(frameName) {} + m_containerType(containerType), + m_containerSrc(containerSrc), + m_containerId(containerId), + m_containerName(containerName) {} TaskAttributionTiming::~TaskAttributionTiming() {} -String TaskAttributionTiming::frameSrc() const { - return m_frameSrc; +String TaskAttributionTiming::containerType() const { + return m_containerType; } -String TaskAttributionTiming::frameId() const { - return m_frameId; +String TaskAttributionTiming::containerSrc() const { + return m_containerSrc; } -String TaskAttributionTiming::frameName() const { - return m_frameName; +String TaskAttributionTiming::containerId() const { + return m_containerId; +} + +String TaskAttributionTiming::containerName() const { + return m_containerName; } DEFINE_TRACE(TaskAttributionTiming) {
diff --git a/third_party/WebKit/Source/core/timing/TaskAttributionTiming.h b/third_party/WebKit/Source/core/timing/TaskAttributionTiming.h index 80699d3..56b6feb5 100644 --- a/third_party/WebKit/Source/core/timing/TaskAttributionTiming.h +++ b/third_party/WebKit/Source/core/timing/TaskAttributionTiming.h
@@ -17,15 +17,18 @@ public: static TaskAttributionTiming* create(String type, - String frameSrc, - String frameId, - String frameName) { - return new TaskAttributionTiming(type, frameSrc, frameId, frameName); + String containerType, + String containerSrc, + String containerId, + String containerName) { + return new TaskAttributionTiming(type, containerType, containerSrc, + containerId, containerName); } - String frameSrc() const; - String frameId() const; - String frameName() const; + String containerType() const; + String containerSrc() const; + String containerId() const; + String containerName() const; DECLARE_VIRTUAL_TRACE(); @@ -33,13 +36,15 @@ private: TaskAttributionTiming(String type, - String frameSrc, - String frameId, - String frameName); + String containerType, + String containerSrc, + String containerId, + String containerName); - String m_frameSrc; - String m_frameId; - String m_frameName; + String m_containerType; + String m_containerSrc; + String m_containerId; + String m_containerName; }; } // namespace blink
diff --git a/third_party/WebKit/Source/core/timing/TaskAttributionTiming.idl b/third_party/WebKit/Source/core/timing/TaskAttributionTiming.idl index 5d610947..f90ae835 100644 --- a/third_party/WebKit/Source/core/timing/TaskAttributionTiming.idl +++ b/third_party/WebKit/Source/core/timing/TaskAttributionTiming.idl
@@ -6,7 +6,8 @@ [ OriginTrialEnabled=LongTaskObserver, ] interface TaskAttributionTiming : PerformanceEntry { - readonly attribute DOMString frameSrc; - readonly attribute DOMString frameId; - readonly attribute DOMString frameName; + readonly attribute DOMString containerType; + readonly attribute DOMString containerSrc; + readonly attribute DOMString containerId; + readonly attribute DOMString containerName; };
diff --git a/third_party/WebKit/Source/core/timing/WorkerPerformance.cpp b/third_party/WebKit/Source/core/timing/WorkerPerformance.cpp index d729e7eb..6634b1a 100644 --- a/third_party/WebKit/Source/core/timing/WorkerPerformance.cpp +++ b/third_party/WebKit/Source/core/timing/WorkerPerformance.cpp
@@ -33,12 +33,18 @@ #include "core/timing/MemoryInfo.h" #include "core/workers/DedicatedWorkerGlobalScope.h" #include "core/workers/WorkerGlobalScope.h" +#include "public/platform/Platform.h" +#include "public/platform/WebScheduler.h" +#include "public/platform/WebThread.h" #include "wtf/CurrentTime.h" namespace blink { WorkerPerformance::WorkerPerformance(WorkerGlobalScope* context) - : PerformanceBase(context->timeOrigin()), m_executionContext(context) {} + : PerformanceBase( + context->timeOrigin(), + Platform::current()->currentThread()->scheduler()->timerTaskRunner()), + m_executionContext(context) {} DEFINE_TRACE(WorkerPerformance) { visitor->trace(m_executionContext);
diff --git a/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js b/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js index ab85581..c7a2462 100644 --- a/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js +++ b/third_party/WebKit/Source/devtools/front_end/accessibility/AXTreePane.js
@@ -13,6 +13,7 @@ this._axSidebarView = axSidebarView; this._treeOutline = this.createTreeOutline(); + this._treeOutline.setPaddingSize(12); this.element.classList.add('accessibility-computed');
diff --git a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityNodeView.js b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityNodeView.js index 5bdfdc3b..9e8664c 100644 --- a/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityNodeView.js +++ b/third_party/WebKit/Source/devtools/front_end/accessibility/AccessibilityNodeView.js
@@ -188,15 +188,13 @@ /** * @param {!Protocol.Accessibility.AXValue} value - * @return {?Element} */ appendValueElement(value) { var AXValueType = Protocol.Accessibility.AXValueType; if (value.type === AXValueType.Idref || value.type === AXValueType.Node || value.type === AXValueType.IdrefList || value.type === AXValueType.NodeList) { this.appendRelatedNodeListValueElement(value); - if (!value.value) - return null; + return; } else if (value.sources) { var sources = value.sources; for (var i = 0; i < sources.length; i++) { @@ -208,7 +206,6 @@ } var element = Accessibility.AXNodePropertyTreeElement.createSimpleValueElement(value.type, String(value.value)); this.listItemElement.appendChild(element); - return element; } /** @@ -303,9 +300,7 @@ this.listItemElement.createChild('span', 'separator').textContent = ':\u00A0'; - var valueElement = this.appendValueElement(this._property.value); - if (this._property.name === 'name') - valueElement.classList.add('ax-computed-text'); + this.appendValueElement(this._property.value); } }; @@ -450,6 +445,8 @@ } else if (this._source.nativeSourceValue) { this.appendValueElement(this._source.nativeSourceValue); this.listItemElement.createTextChild('\u00a0'); + if (this._source.value) + this.appendValueElement(this._source.value); } else if (this._source.value) { this.appendValueElement(this._source.value); } else { @@ -462,20 +459,6 @@ if (this._source.value && this._source.superseded) this.listItemElement.classList.add('ax-value-source-superseded'); } - - /** - * @param {!Protocol.Accessibility.AXValue} value - * @return {!Element} - * @override - */ - appendValueElement(value) { - var element = super.appendValueElement(value); - if (!element) { - element = Accessibility.AXNodePropertyTreeElement.createSimpleValueElement(value.type, String(value.value)); - this.listItemElement.appendChild(element); - } - return element; - } }; /**
diff --git a/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js b/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js index 99e46546..b32588b 100644 --- a/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js +++ b/third_party/WebKit/Source/devtools/front_end/ui/treeoutline.js
@@ -51,6 +51,10 @@ this.element = this.contentElement; + // Adjust to allow computing margin-left for the selection element. + // Check the padding-left for the li element for correct value. + this._paddingSize = 0; + /** * @param {boolean} isFocused * @this {UI.TreeOutline} @@ -209,6 +213,13 @@ } /** + * @param {number} paddingSize + */ + setPaddingSize(paddingSize) { + this._paddingSize = paddingSize; + } + + /** * @param {!Event} event */ _treeKeyDown(event) { @@ -752,11 +763,27 @@ } } + /** + * @return {number} + */ + computeLeftMargin() { + var treeElement = this.parent; + var depth = 0; + while (treeElement !== null) { + depth++; + treeElement = treeElement.parent; + } + + return -(this.treeOutline._paddingSize * (depth - 1) + 4); + } + _ensureSelection() { if (!this.treeOutline || !this.treeOutline._renderSelection) return; if (!this._selectionElement) this._selectionElement = createElementWithClass('div', 'selection fill'); + if (this.treeOutline._paddingSize) + this._selectionElement.style.setProperty('margin-left', this.computeLeftMargin() + 'px'); this._listItemNode.insertBefore(this._selectionElement, this.listItemElement.firstChild); }
diff --git a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp index 8f25c79..0623c9b 100644 --- a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp +++ b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp
@@ -1733,6 +1733,19 @@ return false; } +bool AXNodeObject::nameFromContents() const { + Node* node = getNode(); + if (!node || !node->isElementNode()) + return AXObject::nameFromContents(); + // AXObject::nameFromContents determines whether an element should take its + // name from its descendant contents based on role. However, <select> is a + // special case, as unlike a typical pop-up button it contains its own pop-up + // menu's contents, which should not be used as the name. + if (isHTMLSelectElement(node)) + return false; + return AXObject::nameFromContents(); +} + void AXNodeObject::getRelativeBounds(AXObject** outContainer, FloatRect& outBoundsInContainer, SkMatrix44& outContainerTransform) const { @@ -2256,10 +2269,12 @@ ++labelIndex) { Element* label = labels->item(labelIndex); if (nameSources) { - if (label->getAttribute(forAttr) == htmlElement->getIdAttribute()) + if (!label->getAttribute(forAttr).isEmpty() && + label->getAttribute(forAttr) == htmlElement->getIdAttribute()) { nameSources->back().nativeSource = AXTextFromNativeHTMLLabelFor; - else + } else { nameSources->back().nativeSource = AXTextFromNativeHTMLLabelWrapped; + } } labelElements.push_back(label); } @@ -2300,6 +2315,28 @@ return textAlternative; } } + + // Get default value if object is not laid out. + // If object is laid out, it will have a layout object for the label. + if (!getLayoutObject()) { + String defaultLabel = inputElement->valueOrDefaultLabel(); + if (value.isNull() && !defaultLabel.isNull()) { + // default label + nameFrom = AXNameFromContents; + if (nameSources) { + nameSources->append(NameSource(*foundTextAlternative)); + nameSources->back().type = nameFrom; + } + textAlternative = defaultLabel; + if (nameSources) { + NameSource& source = nameSources->back(); + source.text = textAlternative; + *foundTextAlternative = true; + } else { + return textAlternative; + } + } + } return textAlternative; }
diff --git a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.h b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.h index 80759028..a817bac 100644 --- a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.h +++ b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.h
@@ -177,6 +177,7 @@ AXRelatedObjectVector*) const override; String placeholder(AXNameFrom) const override; bool nameFromLabelElement() const override; + bool nameFromContents() const override; // Location void getRelativeBounds(AXObject** outContainer,
diff --git a/third_party/WebKit/Source/modules/eventsource/EventSource.cpp b/third_party/WebKit/Source/modules/eventsource/EventSource.cpp index f8be89b6..42a8740 100644 --- a/third_party/WebKit/Source/modules/eventsource/EventSource.cpp +++ b/third_party/WebKit/Source/modules/eventsource/EventSource.cpp
@@ -39,6 +39,7 @@ #include "core/dom/Document.h" #include "core/dom/ExceptionCode.h" #include "core/dom/ExecutionContext.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/events/Event.h" #include "core/events/MessageEvent.h" #include "core/frame/LocalDOMWindow.h" @@ -70,7 +71,9 @@ m_currentURL(url), m_withCredentials(eventSourceInit.withCredentials()), m_state(kConnecting), - m_connectTimer(this, &EventSource::connectTimerFired), + m_connectTimer(TaskRunnerHelper::get(TaskType::RemoteEvent, context), + this, + &EventSource::connectTimerFired), m_reconnectDelay(defaultReconnectDelay) {} EventSource* EventSource::create(ExecutionContext* context,
diff --git a/third_party/WebKit/Source/modules/eventsource/EventSource.h b/third_party/WebKit/Source/modules/eventsource/EventSource.h index 80c30cb..33b22ee 100644 --- a/third_party/WebKit/Source/modules/eventsource/EventSource.h +++ b/third_party/WebKit/Source/modules/eventsource/EventSource.h
@@ -134,7 +134,7 @@ Member<EventSourceParser> m_parser; Member<ThreadableLoader> m_loader; - Timer<EventSource> m_connectTimer; + TaskRunnerTimer<EventSource> m_connectTimer; unsigned long long m_reconnectDelay; String m_eventStreamOrigin;
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.cpp b/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.cpp index 09581e7..7b9b4f98 100644 --- a/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.cpp +++ b/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.cpp
@@ -29,6 +29,7 @@ #include "bindings/core/v8/ExceptionState.h" #include "core/dom/ExceptionCode.h" #include "core/dom/ExecutionContext.h" +#include "core/dom/TaskRunnerHelper.h" #include "modules/mediastream/MediaStreamTrack.h" #include "modules/peerconnection/RTCDTMFToneChangeEvent.h" #include "public/platform/WebMediaStreamTrack.h" @@ -72,7 +73,10 @@ m_interToneGap(defaultInterToneGapMs), m_handler(std::move(handler)), m_stopped(false), - m_scheduledEventTimer(this, &RTCDTMFSender::scheduledEventTimerFired) { + m_scheduledEventTimer( + TaskRunnerHelper::get(TaskType::Networking, context), + this, + &RTCDTMFSender::scheduledEventTimerFired) { m_handler->setClient(this); }
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.h b/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.h index bc352fb..e9e4342 100644 --- a/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.h +++ b/third_party/WebKit/Source/modules/peerconnection/RTCDTMFSender.h
@@ -97,7 +97,7 @@ bool m_stopped; - Timer<RTCDTMFSender> m_scheduledEventTimer; + TaskRunnerTimer<RTCDTMFSender> m_scheduledEventTimer; HeapVector<Member<Event>> m_scheduledEvents; };
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.cpp b/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.cpp index 890202a3..afdf569 100644 --- a/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.cpp +++ b/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.cpp
@@ -29,6 +29,7 @@ #include "core/dom/DOMArrayBufferView.h" #include "core/dom/ExceptionCode.h" #include "core/dom/ExecutionContext.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/events/MessageEvent.h" #include "core/fileapi/Blob.h" #include "modules/peerconnection/RTCPeerConnection.h" @@ -88,7 +89,10 @@ m_handler(std::move(handler)), m_readyState(ReadyStateConnecting), m_binaryType(BinaryTypeArrayBuffer), - m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired), + m_scheduledEventTimer( + TaskRunnerHelper::get(TaskType::Networking, context), + this, + &RTCDataChannel::scheduledEventTimerFired), m_bufferedAmountLowThreshold(0U), m_stopped(false) { m_handler->setClient(this);
diff --git a/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.h b/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.h index 4dacc5f9..2b73ee1 100644 --- a/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.h +++ b/third_party/WebKit/Source/modules/peerconnection/RTCDataChannel.h
@@ -135,7 +135,7 @@ enum BinaryType { BinaryTypeBlob, BinaryTypeArrayBuffer }; BinaryType m_binaryType; - Timer<RTCDataChannel> m_scheduledEventTimer; + TaskRunnerTimer<RTCDataChannel> m_scheduledEventTimer; HeapVector<Member<Event>> m_scheduledEvents; unsigned m_bufferedAmountLowThreshold;
diff --git a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp index 24199de..900b0a2 100644 --- a/third_party/WebKit/Source/modules/vr/VRDisplay.cpp +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.cpp
@@ -10,6 +10,7 @@ #include "core/dom/FrameRequestCallback.h" #include "core/dom/Fullscreen.h" #include "core/dom/ScriptedAnimationController.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/frame/UseCounter.h" #include "core/inspector/ConsoleMessage.h" #include "core/loader/DocumentLoader.h" @@ -90,7 +91,11 @@ m_eyeParametersRight(new VREyeParameters()), m_depthNear(0.01), m_depthFar(10000.0), - m_fullscreenCheckTimer(this, &VRDisplay::onFullscreenCheck), + m_fullscreenCheckTimer( + TaskRunnerHelper::get(TaskType::UnspecedTimer, + navigatorVR->document()->frame()), + this, + &VRDisplay::onFullscreenCheck), m_contextGL(nullptr), m_animationCallbackRequested(false), m_inAnimationFrame(false),
diff --git a/third_party/WebKit/Source/modules/vr/VRDisplay.h b/third_party/WebKit/Source/modules/vr/VRDisplay.h index 8a37ac5..92cc1f4 100644 --- a/third_party/WebKit/Source/modules/vr/VRDisplay.h +++ b/third_party/WebKit/Source/modules/vr/VRDisplay.h
@@ -151,7 +151,7 @@ void dispose(); - Timer<VRDisplay> m_fullscreenCheckTimer; + TaskRunnerTimer<VRDisplay> m_fullscreenCheckTimer; String m_fullscreenOrigWidth; String m_fullscreenOrigHeight; gpu::gles2::GLES2Interface* m_contextGL;
diff --git a/third_party/WebKit/Source/web/ValidationMessageClientImpl.cpp b/third_party/WebKit/Source/web/ValidationMessageClientImpl.cpp index d2f3f73..294af07 100644 --- a/third_party/WebKit/Source/web/ValidationMessageClientImpl.cpp +++ b/third_party/WebKit/Source/web/ValidationMessageClientImpl.cpp
@@ -26,6 +26,7 @@ #include "web/ValidationMessageClientImpl.h" #include "core/dom/Element.h" +#include "core/dom/TaskRunnerHelper.h" #include "core/frame/FrameView.h" #include "platform/HostWindow.h" #include "public/platform/WebRect.h" @@ -41,8 +42,7 @@ : m_webView(webView), m_currentAnchor(nullptr), m_lastPageScaleFactor(1), - m_finishTime(0), - m_timer(this, &ValidationMessageClientImpl::checkAnchorStatus) {} + m_finishTime(0) {} ValidationMessageClientImpl* ValidationMessageClientImpl::create( WebViewImpl& webView) { @@ -90,13 +90,16 @@ (message.length() + subMessage.length()) * secondPerCharacter); // FIXME: We should invoke checkAnchorStatus actively when layout, scroll, // or page scale change happen. - m_timer.startRepeating(statusCheckInterval, BLINK_FROM_HERE); + m_timer = WTF::makeUnique<TaskRunnerTimer<ValidationMessageClientImpl>>( + TaskRunnerHelper::get(TaskType::UnspecedTimer, &anchor.document()), this, + &ValidationMessageClientImpl::checkAnchorStatus); + m_timer->startRepeating(statusCheckInterval, BLINK_FROM_HERE); } void ValidationMessageClientImpl::hideValidationMessage(const Element& anchor) { if (!m_currentAnchor || !isValidationMessageVisible(anchor)) return; - m_timer.stop(); + m_timer = nullptr; m_currentAnchor = nullptr; m_message = String(); m_finishTime = 0;
diff --git a/third_party/WebKit/Source/web/ValidationMessageClientImpl.h b/third_party/WebKit/Source/web/ValidationMessageClientImpl.h index 73c81e4..dc308d3 100644 --- a/third_party/WebKit/Source/web/ValidationMessageClientImpl.h +++ b/third_party/WebKit/Source/web/ValidationMessageClientImpl.h
@@ -69,7 +69,7 @@ IntRect m_lastAnchorRectInScreen; float m_lastPageScaleFactor; double m_finishTime; - Timer<ValidationMessageClientImpl> m_timer; + std::unique_ptr<TimerBase> m_timer; }; } // namespace blink
diff --git a/third_party/WebKit/Source/web/WebViewImpl.cpp b/third_party/WebKit/Source/web/WebViewImpl.cpp index 20a7668e..67bb3888 100644 --- a/third_party/WebKit/Source/web/WebViewImpl.cpp +++ b/third_party/WebKit/Source/web/WebViewImpl.cpp
@@ -1392,7 +1392,7 @@ while (node) { if (node->layoutObject()) { ECursor cursor = node->layoutObject()->style()->cursor(); - if (cursor != ECursor::Auto || + if (cursor != ECursor::kAuto || frame->eventHandler().useHandCursor(node, node->isLink())) break; } @@ -1407,8 +1407,8 @@ return false; ECursor cursor = node->layoutObject()->style()->cursor(); - return cursor == ECursor::Pointer || - (cursor == ECursor::Auto && + return cursor == ECursor::kPointer || + (cursor == ECursor::kAuto && frame->eventHandler().useHandCursor(node, node->isLink())); }
diff --git a/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp b/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp index 8a45a84..b02f7c5 100644 --- a/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp +++ b/third_party/WebKit/Source/web/tests/ResizeObserverTest.cpp
@@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "core/observer/ResizeObserver.h" +#include "core/dom/ResizeObserver.h" #include "bindings/core/v8/ScriptController.h" #include "bindings/core/v8/ScriptSourceCode.h" #include "bindings/core/v8/V8GCController.h" -#include "core/observer/ResizeObservation.h" -#include "core/observer/ResizeObserverCallback.h" -#include "core/observer/ResizeObserverController.h" +#include "core/dom/ResizeObservation.h" +#include "core/dom/ResizeObserverCallback.h" +#include "core/dom/ResizeObserverController.h" #include "platform/testing/UnitTestHelpers.h" #include "public/web/WebHeap.h" #include "web/WebViewImpl.h"
diff --git a/third_party/bintrees/LICENSE.txt b/third_party/bintrees/LICENSE.txt deleted file mode 100644 index 3b2c783e..0000000 --- a/third_party/bintrees/LICENSE.txt +++ /dev/null
@@ -1,45 +0,0 @@ -Copyright (c) 2012, Manfred Moitzi - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Deutsche Übersetzung: - -Copyright (c) 2012, Manfred Moitzi - -Hiermit wird unentgeltlich, jeder Person, die eine Kopie der Software -und der zugehörigen Dokumentationen (die "Software") erhält, die -Erlaubnis erteilt, uneingeschränkt zu benutzen, inklusive und ohne -Ausnahme, dem Recht, sie zu verwenden, kopieren, ändern, fusionieren, -verlegen, verbreiten, unterlizenzieren und/oder zu verkaufen, und -Personen, die diese Software erhalten, diese Rechte zu geben, unter den -folgenden Bedingungen: - -Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in allen -Kopien oder Teilkopien der Software beizulegen. - -DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIE -BEREITGESTELLT, EINSCHLIESSLICH DER GARANTIE ZUR BENUTZUNG FÜR DEN -VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER -RECHTSVERLETZUNG, JEDOCH NICHT DARAUF BESCHRÄNKT. IN KEINEM FALL SIND -DIE AUTOREN ODER COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER SONSTIGE -ANSPRÜCHE HAFTBAR ZU MACHEN, OB INFOLGE DER ERFÜLLUNG EINES VERTRAGES, -EINES DELIKTES ODER ANDERS IM ZUSAMMENHANG MIT DER SOFTWARE ODER -SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN. -
diff --git a/third_party/bintrees/NEWS.txt b/third_party/bintrees/NEWS.txt deleted file mode 100644 index c87ea15..0000000 --- a/third_party/bintrees/NEWS.txt +++ /dev/null
@@ -1,70 +0,0 @@ -Version 1.0.1 February 2013 - - * bug fixes - * refactorings by graingert - * skip useless tests for pypy - * new license: MIT License - * tested with CPython2.7, CPython3.2, CPython3.3, pypy-1.9, pypy-2.0-beta1 - * unified line endings to LF - * PEP8 refactorings - * added floor_item/key, ceiling_item/key methods, thanks to Dai Mikurube - -Version 1.0.0 29.12.2011 - - * bug fixes - * status: 5 - Production/Stable - * removed useless TreeIterator() class and T.treeiter() method. - * patch from Max Motovilov to use Visual Studio 2008 for building C-extensions - -Version 0.4.0 14.04.2011 - - * API change!!! - * full Python 3 support, also for Cython implementations - * removed user defined compare() function - keys have to be comparable! - * removed T.has_key(), use 'key in T' - * keys(), items(), values() generating 'views' - * removed iterkeys(), itervalues(), iteritems() methods - * replaced index slicing by key slicing - * removed index() and item_at() - * repr() produces a correct representation - * installs on systems without cython (tested with pypy) - * new license: GNU Library or Lesser General Public License (LGPL) - -Version 0.3.2 09.04.2011 - - * added itemslice(startkey, endkey), keyslice(startkey, endkey), - valueslice(startkey, endkey) - slicing by keys - * tested with pypy 1.4.1, damn fast - * Pure Python trees are working with Python 3 - * No Cython implementation for Python 3 - -Version 0.3.1 10.09.2010 - - * runs with Python 2.7 - -Version 0.3.0 11.05.2010 - - * low level functions written as c-module only interface to python is a cython - module - * support for the pickle protocol - -Version 0.2.1 06.05.2010 - - * added delslice del T[0:3] -> remove treenodes 0, 1, 2 - * added discard -> remove key without KeyError if not found - * added heap methods: min, max, nlarges, nsmallest ... - * added Set methods -> intersection, differnce, union, ... - * added slicing: T[5:10] get items with position (not key!) 5, 6, 7, 8, 9 - T[5] get item with key! 5 - * added index: T.index(key) -> get position of item <key> - * added item_at: T.item_at(0) -> get item at position (not key!) 0 - T.item_at(0) O(n)! <==> T.min_item() O(log(n)) - -Version 0.2.0 - 03.05.2010 - - * TreeMixin Class as base for Python-Trees and as Mixin for Cython-Trees - -Version 0.1.0 - 27.04.2010 - - * Alpha status - * Initial release
diff --git a/third_party/bintrees/OWNERS b/third_party/bintrees/OWNERS deleted file mode 100644 index cf261a7..0000000 --- a/third_party/bintrees/OWNERS +++ /dev/null
@@ -1,2 +0,0 @@ -dmikurube@chromium.org -peria@chromium.org
diff --git a/third_party/bintrees/README.chromium b/third_party/bintrees/README.chromium deleted file mode 100644 index bd47bae7..0000000 --- a/third_party/bintrees/README.chromium +++ /dev/null
@@ -1,15 +0,0 @@ -Name: Binary-, RedBlack- and AVL-Trees in Python and Cython -Short Name: bintrees -URL: https://pypi.python.org/pypi/bintrees/ -Version: 1.0.1 -Date: February 24, 2013 -License: MIT -License File: NOT_SHIPPED -Security Critical: no - -Description: -A Python library which provides Binary-, RedBlack- and AVL-Trees in Python and -Cython. - -Local Modifications: -Removed PKG-INFO, setup.py and tests.
diff --git a/third_party/bintrees/README.txt b/third_party/bintrees/README.txt deleted file mode 100644 index ba81360..0000000 --- a/third_party/bintrees/README.txt +++ /dev/null
@@ -1,229 +0,0 @@ -Binary Tree Package -=================== - -Abstract -======== - -This package provides Binary- RedBlack- and AVL-Trees written in Python and Cython. - -This Classes are much slower than the built-in dict class, but all -iterators/generators yielding data in sorted key order. - -Source of Algorithms --------------------- - -AVL- and RBTree algorithms taken from Julienne Walker: http://eternallyconfuzzled.com/jsw_home.aspx - -Trees written in Python (only standard library) ------------------------------------------------ - - - *BinaryTree* -- unbalanced binary tree - - *AVLTree* -- balanced AVL-Tree - - *RBTree* -- balanced Red-Black-Tree - -Trees written with C-Functions and Cython as wrapper ----------------------------------------------------- - - - *FastBinaryTree* -- unbalanced binary tree - - *FastAVLTree* -- balanced AVL-Tree - - *FastRBTree* -- balanced Red-Black-Tree - -All trees provides the same API, the pickle protocol is supported. - -FastXTrees has C-structs as tree-node structure and C-implementation for low level -operations: insert, remove, get_value, max_item, min_item. - -Constructor -~~~~~~~~~~~ - - * Tree() -> new empty tree; - * Tree(mapping) -> new tree initialized from a mapping (requires only an items() method) - * Tree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)] - -Methods -~~~~~~~ - - * __contains__(k) -> True if T has a key k, else False, O(log(n)) - * __delitem__(y) <==> del T[y], del[s:e], O(log(n)) - * __getitem__(y) <==> T[y], T[s:e], O(log(n)) - * __iter__() <==> iter(T) - * __len__() <==> len(T), O(1) - * __max__() <==> max(T), get max item (k,v) of T, O(log(n)) - * __min__() <==> min(T), get min item (k,v) of T, O(log(n)) - * __and__(other) <==> T & other, intersection - * __or__(other) <==> T | other, union - * __sub__(other) <==> T - other, difference - * __xor__(other) <==> T ^ other, symmetric_difference - * __repr__() <==> repr(T) - * __setitem__(k, v) <==> T[k] = v, O(log(n)) - * clear() -> None, remove all items from T, O(n) - * copy() -> a shallow copy of T, O(n*log(n)) - * discard(k) -> None, remove k from T, if k is present, O(log(n)) - * get(k[,d]) -> T[k] if k in T, else d, O(log(n)) - * is_empty() -> True if len(T) == 0, O(1) - * items([reverse]) -> generator for (k, v) items of T, O(n) - * keys([reverse]) -> generator for keys of T, O(n) - * values([reverse]) -> generator for values of T, O(n) - * pop(k[,d]) -> v, remove specified key and return the corresponding value, O(log(n)) - * popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple, O(log(n)) - * setdefault(k[,d]) -> T.get(k, d), also set T[k]=d if k not in T, O(log(n)) - * update(E) -> None. Update T from dict/iterable E, O(E*log(n)) - * foreach(f, [order]) -> visit all nodes of tree (0 = 'inorder', -1 = 'preorder' or +1 = 'postorder') and call f(k, v) for each node, O(n) - -slicing by keys -~~~~~~~~~~~~~~~ - - * itemslice(s, e) -> generator for (k, v) items of T for s <= key < e, O(n) - * keyslice(s, e) -> generator for keys of T for s <= key < e, O(n) - * valueslice(s, e) -> generator for values of T for s <= key < e, O(n) - * T[s:e] -> TreeSlice object, with keys in range s <= key < e, O(n) - * del T[s:e] -> remove items by key slicing, for s <= key < e, O(n) - - start/end parameter: - - * if 's' is None or T[:e] TreeSlice/iterator starts with value of min_key(); - * if 'e' is None or T[s:] TreeSlice/iterator ends with value of max_key(); - * T[:] is a TreeSlice which represents the whole tree; - - TreeSlice is a tree wrapper with range check, and contains no references - to objects, deleting objects in the associated tree also deletes the object - in the TreeSlice. - - * TreeSlice[k] -> get value for key k, raises KeyError if k not exists in range s:e - * TreeSlice[s1:e1] -> TreeSlice object, with keys in range s1 <= key < e1 - - new lower bound is max(s, s1) - - new upper bound is min(e, e1) - - TreeSlice methods: - - * items() -> generator for (k, v) items of T, O(n) - * keys() -> generator for keys of T, O(n) - * values() -> generator for values of T, O(n) - * __iter__ <==> keys() - * __repr__ <==> repr(T) - * __contains__(key)-> True if TreeSlice has a key k, else False, O(log(n)) - -prev/succ operations -~~~~~~~~~~~~~~~~~~~~ - - * prev_item(key) -> get (k, v) pair, where k is predecessor to key, O(log(n)) - * prev_key(key) -> k, get the predecessor of key, O(log(n)) - * succ_item(key) -> get (k,v) pair as a 2-tuple, where k is successor to key, O(log(n)) - * succ_key(key) -> k, get the successor of key, O(log(n)) - * floor_item(key) -> get (k, v) pair, where k is the greatest key less than or equal to key, O(log(n)) - * floor_key(key) -> k, get the greatest key less than or equal to key, O(log(n)) - * ceiling_item(key) -> get (k, v) pair, where k is the smallest key greater than or equal to key, O(log(n)) - * ceiling_key(key) -> k, get the smallest key greater than or equal to key, O(log(n)) - -Heap methods -~~~~~~~~~~~~ - - * max_item() -> get largest (key, value) pair of T, O(log(n)) - * max_key() -> get largest key of T, O(log(n)) - * min_item() -> get smallest (key, value) pair of T, O(log(n)) - * min_key() -> get smallest key of T, O(log(n)) - * pop_min() -> (k, v), remove item with minimum key, O(log(n)) - * pop_max() -> (k, v), remove item with maximum key, O(log(n)) - * nlargest(i[,pop]) -> get list of i largest items (k, v), O(i*log(n)) - * nsmallest(i[,pop]) -> get list of i smallest items (k, v), O(i*log(n)) - -Set methods (using frozenset) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - * intersection(t1, t2, ...) -> Tree with keys *common* to all trees - * union(t1, t2, ...) -> Tree with keys from *either* trees - * difference(t1, t2, ...) -> Tree with keys in T but not any of t1, t2, ... - * symmetric_difference(t1) -> Tree with keys in either T and t1 but not both - * issubset(S) -> True if every element in T is in S - * issuperset(S) -> True if every element in S is in T - * isdisjoint(S) -> True if T has a null intersection with S - -Classmethods -~~~~~~~~~~~~ - - * fromkeys(S[,v]) -> New tree with keys from S and values equal to v. - -Performance -=========== - -Profiling with timeit(): 5000 unique random int keys, time in seconds - -======================== ============= ============== ============== ============== -unbalanced Trees CPython 2.7.2 FastBinaryTree ipy 2.7.0 pypy 1.7.0 -======================== ============= ============== ============== ============== -build time 100x 7,55 0,60 2,51 0,29 -build & delete time 100x 13,34 1,48 4,45 0,47 -search 100x all keys 2,86 0,96 0,27 0,06 -======================== ============= ============== ============== ============== - -======================== ============= ============== ============== ============== -AVLTrees CPython 2.7.2 FastAVLTree ipy 2.7.0 pypy 1.7.0 -======================== ============= ============== ============== ============== -build time 100x 22,66 0,65 10,45 1,29 -build & delete time 100x 36,71 1,47 20,89 3,02 -search 100x all keys 2,34 0,85 0,89 0,14 -======================== ============= ============== ============== ============== - -======================== ============= ============== ============== ============== -RBTrees CPython 2.7.2 FastRBTree ipy 2.7.0 pypy 1.7.0 -======================== ============= ============== ============== ============== -build time 100x 14,78 0,65 4,43 0,49 -build & delete time 100x 39,34 1,63 12,43 1,32 -search 100x all keys 2,32 0,86 0,86 0,13 -======================== ============= ============== ============== ============== - -News -==== - -Version 1.0.1 February 2013 - - * bug fixes - * refactorings by graingert - * skip useless tests for pypy - * new license: MIT License - * tested with CPython2.7, CPython3.2, CPython3.3, pypy-1.9, pypy-2.0-beta1 - * unified line endings to LF - * PEP8 refactorings - * added floor_item/key, ceiling_item/key methods, thanks to Dai Mikurube - -Version 1.0.0 - - * bug fixes - * status: 5 - Production/Stable - * removed useless TreeIterator() class and T.treeiter() method. - * patch from Max Motovilov to use Visual Studio 2008 for building C-extensions - -Version 0.4.0 - - * API change!!! - * full Python 3 support, also for Cython implementations - * removed user defined compare() function - keys have to be comparable! - * removed T.has_key(), use 'key in T' - * keys(), items(), values() generating 'views' - * removed iterkeys(), itervalues(), iteritems() methods - * replaced index slicing by key slicing - * removed index() and item_at() - * repr() produces a correct representation - * installs on systems without cython (tested with pypy) - * new license: GNU Library or Lesser General Public License (LGPL) - -Installation -============ - -from source:: - - python setup.py install - -Download -======== - -http://bitbucket.org/mozman/bintrees/downloads - -Documentation -============= - -this README.txt - -bintrees can be found on bitbucket.org at: - -http://bitbucket.org/mozman/bintrees
diff --git a/third_party/bintrees/bintrees/__init__.py b/third_party/bintrees/bintrees/__init__.py deleted file mode 100644 index 8cb5de1..0000000 --- a/third_party/bintrees/bintrees/__init__.py +++ /dev/null
@@ -1,181 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: binary trees package -# Created: 03.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -from __future__ import absolute_import - -__doc__ = """ -Binary Tree Package -=================== - -Python Trees ------------- - -Balanced and unbalance binary trees written in pure Python with a dict-like API. - -Classes -~~~~~~~ -* BinaryTree -- unbalanced binary tree -* AVLTree -- balanced AVL-Tree -* RBTree -- balanced Red-Black-Tree - -Cython Trees ------------- - -Basic tree functions written in Cython, merged with TreeMixin to provide the -full API of the Python Trees. - -Classes -~~~~~~~ - -* FastBinaryTree -- unbalanced binary tree -* FastAVLTree -- balanced AVLTree -* FastRBTree -- balanced Red-Black-Tree - -Overview of API for all Classes -=============================== - -* TreeClass ([compare]) -> new empty tree. -* TreeClass(mapping, [compare]) -> new tree initialized from a mapping -* TreeClass(seq, [compare]) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)] - -Methods -------- - -* __contains__(k) -> True if T has a key k, else False, O(log(n)) -* __delitem__(y) <==> del T[y], O(log(n)) -* __getitem__(y) <==> T[y], O(log(n)) -* __iter__() <==> iter(T) -* __len__() <==> len(T), O(1) -* __max__() <==> max(T), get max item (k,v) of T, O(log(n)) -* __min__() <==> min(T), get min item (k,v) of T, O(log(n)) -* __and__(other) <==> T & other, intersection -* __or__(other) <==> T | other, union -* __sub__(other) <==> T - other, difference -* __xor__(other) <==> T ^ other, symmetric_difference -* __repr__() <==> repr(T) -* __setitem__(k, v) <==> T[k] = v, O(log(n)) -* clear() -> None, Remove all items from T, , O(n) -* copy() -> a shallow copy of T, O(n*log(n)) -* discard(k) -> None, remove k from T, if k is present, O(log(n)) -* get(k[,d]) -> T[k] if k in T, else d, O(log(n)) -* is_empty() -> True if len(T) == 0, O(1) -* items([reverse]) -> list of T's (k, v) pairs, as 2-tuples, O(n) -* keys([reverse]) -> list of T's keys, O(n) -* pop(k[,d]) -> v, remove specified key and return the corresponding value, O(log(n)) -* popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple, O(log(n)) -* setdefault(k[,d]) -> T.get(k, d), also set T[k]=d if k not in T, O(log(n)) -* update(E) -> None. Update T from dict/iterable E, O(E*log(n)) -* values([reverse]) -> list of T's values, O(n) - -walk forward/backward, O(log(n)) - -* prev_item(key) -> get (k, v) pair, where k is predecessor to key, O(log(n)) -* prev_key(key) -> k, get the predecessor of key, O(log(n)) -* succ_item(key) -> get (k,v) pair as a 2-tuple, where k is successor to key, O(log(n)) -* succ_key(key) -> k, get the successor of key, O(log(n)) - -slicing by keys - -* itemslice(s, e) -> generator for (k, v) items of T for s <= key < e, O(n) -* keyslice(s, e) -> generator for keys of T for s <= key < e, O(n) -* valueslice(s, e) -> generator for values of T for s <= key < e, O(n) -* T[s:e] -> TreeSlice object, with keys in range s <= key < e, O(n) -* del T[s:e] -> remove items by key slicing, for s <= key < e, O(n) - -if 's' is None or T[:e] TreeSlice/iterator starts with value of min_key() -if 'e' is None or T[s:] TreeSlice/iterator ends with value of max_key() -T[:] is a TreeSlice which represents the whole tree. - -TreeSlice is a tree wrapper with range check, and contains no references -to objects, deleting objects in the associated tree also deletes the object -in the TreeSlice. - -* TreeSlice[k] -> get value for key k, raises KeyError if k not exists in range s:e -* TreeSlice[s1:e1] -> TreeSlice object, with keys in range s1 <= key < e1 - - * new lower bound is max(s, s1) - * new upper bound is min(e, e1) - -TreeSlice methods: - -* items() -> generator for (k, v) items of T, O(n) -* keys() -> generator for keys of T, O(n) -* values() -> generator for values of T, O(n) -* __iter__ <==> keys() -* __repr__ <==> repr(T) -* __contains__(key)-> True if TreeSlice has a key k, else False, O(log(n)) - -Heap methods - -* max_item() -> get biggest (key, value) pair of T, O(log(n)) -* max_key() -> get biggest key of T, O(log(n)) -* min_item() -> get smallest (key, value) pair of T, O(log(n)) -* min_key() -> get smallest key of T, O(log(n)) -* pop_min() -> (k, v), remove item with minimum key, O(log(n)) -* pop_max() -> (k, v), remove item with maximum key, O(log(n)) -* nlargest(i[,pop]) -> get list of i largest items (k, v), O(i*log(n)) -* nsmallest(i[,pop]) -> get list of i smallest items (k, v), O(i*log(n)) - -Set methods (using frozenset) - -* intersection(t1, t2, ...) -> Tree with keys *common* to all trees -* union(t1, t2, ...) -> Tree with keys from *either* trees -* difference(t1, t2, ...) -> Tree with keys in T but not any of t1, t2, ... -* symmetric_difference(t1) -> Tree with keys in either T and t1 but not both -* issubset(S) -> True if every element in T is in S -* issuperset(S) -> True if every element in S is in T -* isdisjoint(S) -> True if T has a null intersection with S - -Classmethods - -* fromkeys(S[,v]) -> New tree with keys from S and values equal to v. -""" - -__all__ = [ - 'FastBinaryTree', - 'FastAVLTree', - 'FastRBTree', - 'BinaryTree', - 'AVLTree', - 'RBTree' -] - -from .treemixin import TreeMixin -from .bintree import BinaryTree -from .avltree import AVLTree -from .rbtree import RBTree - -try: - from .qbintree import cBinaryTree - - class FastBinaryTree(cBinaryTree, TreeMixin): - """ Faster unbalanced binary tree written in Cython with C-Code. """ -except ImportError: # fall back to pure Python version - FastBinaryTree = BinaryTree -except ValueError: # for pypy - FastBinaryTree = BinaryTree - -try: - from .qavltree import cAVLTree - - class FastAVLTree(cAVLTree, TreeMixin): - """ Faster balanced AVL-Tree written in Cython with C-Code. """ -except ImportError: # fall back to pure Python version - FastAVLTree = AVLTree -except ValueError: # for pypy - FastAVLTree = AVLTree - -try: - from .qrbtree import cRBTree - - class FastRBTree(cRBTree, TreeMixin): - """ Faster balanced Red-Black-Tree written in Cython with C-Code. """ -except ImportError: # fall back to pure Python version - FastRBTree = RBTree -except ValueError: # for pypy - FastRBTree = RBTree
diff --git a/third_party/bintrees/bintrees/avltree.py b/third_party/bintrees/bintrees/avltree.py deleted file mode 100644 index 632ba4e..0000000 --- a/third_party/bintrees/bintrees/avltree.py +++ /dev/null
@@ -1,302 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman (python version) -# Purpose: avl tree module (Julienne Walker's unbounded none recursive algorithm) -# source: http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_avl.aspx -# Created: 01.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -# Conclusion of Julienne Walker - -# AVL trees are about as close to optimal as balanced binary search trees can -# get without eating up resources. You can rest assured that the O(log N) -# performance of binary search trees is guaranteed with AVL trees, but the extra -# bookkeeping required to maintain an AVL tree can be prohibitive, especially -# if deletions are common. Insertion into an AVL tree only requires one single -# or double rotation, but deletion could perform up to O(log N) rotations, as -# in the example of a worst case AVL (ie. Fibonacci) tree. However, those cases -# are rare, and still very fast. - -# AVL trees are best used when degenerate sequences are common, and there is -# little or no locality of reference in nodes. That basically means that -# searches are fairly random. If degenerate sequences are not common, but still -# possible, and searches are random then a less rigid balanced tree such as red -# black trees or Andersson trees are a better solution. If there is a significant -# amount of locality to searches, such as a small cluster of commonly searched -# items, a splay tree is theoretically better than all of the balanced trees -# because of its move-to-front design. - -from __future__ import absolute_import - -from .treemixin import TreeMixin -from array import array - -__all__ = ['AVLTree'] - -MAXSTACK = 32 - - -class Node(object): - """ Internal object, represents a treenode """ - __slots__ = ['left', 'right', 'balance', 'key', 'value'] - - def __init__(self, key=None, value=None): - self.left = None - self.right = None - self.key = key - self.value = value - self.balance = 0 - - def __getitem__(self, key): - """ x.__getitem__(key) <==> x[key], where key is 0 (left) or 1 (right) """ - return self.left if key == 0 else self.right - - def __setitem__(self, key, value): - """ x.__setitem__(key, value) <==> x[key]=value, where key is 0 (left) or 1 (right) """ - if key == 0: - self.left = value - else: - self.right = value - - def free(self): - """Remove all references.""" - self.left = None - self.right = None - self.key = None - self.value = None - - -def height(node): - return node.balance if node is not None else -1 - - -def jsw_single(root, direction): - other_side = 1 - direction - save = root[other_side] - root[other_side] = save[direction] - save[direction] = root - rlh = height(root.left) - rrh = height(root.right) - slh = height(save[other_side]) - root.balance = max(rlh, rrh) + 1 - save.balance = max(slh, root.balance) + 1 - return save - - -def jsw_double(root, direction): - other_side = 1 - direction - root[other_side] = jsw_single(root[other_side], other_side) - return jsw_single(root, direction) - - -class AVLTree(TreeMixin): - """ - AVLTree implements a balanced binary tree with a dict-like interface. - - see: http://en.wikipedia.org/wiki/AVL_tree - - In computer science, an AVL tree is a self-balancing binary search tree, and - it is the first such data structure to be invented. In an AVL tree, the - heights of the two child subtrees of any node differ by at most one; - therefore, it is also said to be height-balanced. Lookup, insertion, and - deletion all take O(log n) time in both the average and worst cases, where n - is the number of nodes in the tree prior to the operation. Insertions and - deletions may require the tree to be rebalanced by one or more tree rotations. - - The AVL tree is named after its two inventors, G.M. Adelson-Velskii and E.M. - Landis, who published it in their 1962 paper "An algorithm for the - organization of information." - - AVLTree() -> new empty tree. - AVLTree(mapping) -> new tree initialized from a mapping - AVLTree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)] - - see also TreeMixin() class. - - """ - def __init__(self, items=None): - """ x.__init__(...) initializes x; see x.__class__.__doc__ for signature """ - self._root = None - self._count = 0 - if items is not None: - self.update(items) - - def clear(self): - """ T.clear() -> None. Remove all items from T. """ - def _clear(node): - if node is not None: - _clear(node.left) - _clear(node.right) - node.free() - _clear(self._root) - self._count = 0 - self._root = None - - @property - def count(self): - """ count of items """ - return self._count - - @property - def root(self): - """ root node of T """ - return self._root - - def _new_node(self, key, value): - """ Create a new treenode """ - self._count += 1 - return Node(key, value) - - def insert(self, key, value): - """ T.insert(key, value) <==> T[key] = value, insert key, value into Tree """ - if self._root is None: - self._root = self._new_node(key, value) - else: - node_stack = [] # node stack - dir_stack = array('I') # direction stack - done = False - top = 0 - node = self._root - # search for an empty link, save path - while True: - if key == node.key: # update existing item - node.value = value - return - direction = 1 if key > node.key else 0 - dir_stack.append(direction) - node_stack.append(node) - if node[direction] is None: - break - node = node[direction] - - # Insert a new node at the bottom of the tree - node[direction] = self._new_node(key, value) - - # Walk back up the search path - top = len(node_stack) - 1 - while (top >= 0) and not done: - direction = dir_stack[top] - other_side = 1 - direction - topnode = node_stack[top] - left_height = height(topnode[direction]) - right_height = height(topnode[other_side]) - - # Terminate or rebalance as necessary */ - if left_height - right_height == 0: - done = True - if left_height - right_height >= 2: - a = topnode[direction][direction] - b = topnode[direction][other_side] - - if height(a) >= height(b): - node_stack[top] = jsw_single(topnode, other_side) - else: - node_stack[top] = jsw_double(topnode, other_side) - - # Fix parent - if top != 0: - node_stack[top - 1][dir_stack[top - 1]] = node_stack[top] - else: - self._root = node_stack[0] - done = True - - # Update balance factors - topnode = node_stack[top] - left_height = height(topnode[direction]) - right_height = height(topnode[other_side]) - - topnode.balance = max(left_height, right_height) + 1 - top -= 1 - - def remove(self, key): - """ T.remove(key) <==> del T[key], remove item <key> from tree """ - if self._root is None: - raise KeyError(str(key)) - else: - node_stack = [None] * MAXSTACK # node stack - dir_stack = array('I', [0] * MAXSTACK) # direction stack - top = 0 - node = self._root - - while True: - # Terminate if not found - if node is None: - raise KeyError(str(key)) - elif node.key == key: - break - - # Push direction and node onto stack - direction = 1 if key > node.key else 0 - dir_stack[top] = direction - - node_stack[top] = node - node = node[direction] - top += 1 - - # Remove the node - if (node.left is None) or (node.right is None): - # Which child is not null? - direction = 1 if node.left is None else 0 - - # Fix parent - if top != 0: - node_stack[top - 1][dir_stack[top - 1]] = node[direction] - else: - self._root = node[direction] - node.free() - self._count -= 1 - else: - # Find the inorder successor - heir = node.right - - # Save the path - dir_stack[top] = 1 - node_stack[top] = node - top += 1 - - while heir.left is not None: - dir_stack[top] = 0 - node_stack[top] = heir - top += 1 - heir = heir.left - - # Swap data - node.key = heir.key - node.value = heir.value - - # Unlink successor and fix parent - xdir = 1 if node_stack[top - 1].key == node.key else 0 - node_stack[top - 1][xdir] = heir.right - heir.free() - self._count -= 1 - - # Walk back up the search path - top -= 1 - while top >= 0: - direction = dir_stack[top] - other_side = 1 - direction - topnode = node_stack[top] - left_height = height(topnode[direction]) - right_height = height(topnode[other_side]) - b_max = max(left_height, right_height) - - # Update balance factors - topnode.balance = b_max + 1 - - # Terminate or rebalance as necessary - if (left_height - right_height) == -1: - break - if (left_height - right_height) <= -2: - a = topnode[other_side][direction] - b = topnode[other_side][other_side] - if height(a) <= height(b): - node_stack[top] = jsw_single(topnode, direction) - else: - node_stack[top] = jsw_double(topnode, direction) - # Fix parent - if top != 0: - node_stack[top - 1][dir_stack[top - 1]] = node_stack[top] - else: - self._root = node_stack[0] - top -= 1
diff --git a/third_party/bintrees/bintrees/bintree.py b/third_party/bintrees/bintrees/bintree.py deleted file mode 100644 index 866dc89..0000000 --- a/third_party/bintrees/bintrees/bintree.py +++ /dev/null
@@ -1,153 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: binary tree module -# Created: 28.04.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -from __future__ import absolute_import - -from .treemixin import TreeMixin - -__all__ = ['BinaryTree'] - - -class Node(object): - """ Internal object, represents a treenode """ - __slots__ = ['key', 'value', 'left', 'right'] - - def __init__(self, key, value): - self.key = key - self.value = value - self.left = None - self.right = None - - def __getitem__(self, key): - """ x.__getitem__(key) <==> x[key], where key is 0 (left) or 1 (right) """ - return self.left if key == 0 else self.right - - def __setitem__(self, key, value): - """ x.__setitem__(key, value) <==> x[key]=value, where key is 0 (left) or 1 (right) """ - if key == 0: - self.left = value - else: - self.right = value - - def free(self): - """ Set references to None """ - self.left = None - self.right = None - self.value = None - self.key = None - - -class BinaryTree(TreeMixin): - """ - BinaryTree implements an unbalanced binary tree with a dict-like interface. - - see: http://en.wikipedia.org/wiki/Binary_tree - - A binary tree is a tree data structure in which each node has at most two - children. - - BinaryTree() -> new empty tree. - BinaryTree(mapping,) -> new tree initialized from a mapping - BinaryTree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)] - - see also TreeMixin() class. - - """ - def __init__(self, items=None): - """ x.__init__(...) initializes x; see x.__class__.__doc__ for signature """ - self._root = None - self._count = 0 - if items is not None: - self.update(items) - - def clear(self): - """ T.clear() -> None. Remove all items from T. """ - def _clear(node): - if node is not None: - _clear(node.left) - _clear(node.right) - node.free() - _clear(self._root) - self._count = 0 - self._root = None - - @property - def root(self): - """ root node of T """ - return self._root - - @property - def count(self): - """ count of items """ - return self._count - - def _new_node(self, key, value): - """ Create a new tree node. """ - self._count += 1 - return Node(key, value) - - def insert(self, key, value): - """ T.insert(key, value) <==> T[key] = value, insert key, value into Tree """ - if self._root is None: - self._root = self._new_node(key, value) - else: - parent = None - direction = 0 - node = self._root - while True: - if node is None: - parent[direction] = self._new_node(key, value) - break - if key == node.key: - node.value = value # replace value - break - else: - parent = node - direction = 0 if key <= node.key else 1 - node = node[direction] - - def remove(self, key): - """ T.remove(key) <==> del T[key], remove item <key> from tree """ - node = self._root - if node is None: - raise KeyError(str(key)) - else: - parent = None - direction = 0 - while True: - if key == node.key: - # remove node - if (node.left is not None) and (node.right is not None): - # find replacment node: smallest key in right-subtree - parent = node - direction = 1 - replacement = node.right - while replacement.left is not None: - parent = replacement - direction = 0 - replacement = replacement.left - parent[direction] = replacement.right - #swap places - node.key = replacement.key - node.value = replacement.value - node = replacement # delete replacement! - else: - down_dir = 1 if node.left is None else 0 - if parent is None: # root - self._root = node[down_dir] - else: - parent[direction] = node[down_dir] - node.free() - self._count -= 1 - break - else: - direction = 0 if key < node.key else 1 - parent = node - node = node[direction] - if node is None: - raise KeyError(str(key))
diff --git a/third_party/bintrees/bintrees/ctrees.c b/third_party/bintrees/bintrees/ctrees.c deleted file mode 100644 index 7d2b964..0000000 --- a/third_party/bintrees/bintrees/ctrees.c +++ /dev/null
@@ -1,862 +0,0 @@ -/* - * ctrees.c - * - * Author: mozman - * Copyright (c) 2010-2013 by Manfred Moitzi - * License: MIT-License - */ - -#include "ctrees.h" -#include "stack.h" -#include <Python.h> - -#define LEFT 0 -#define RIGHT 1 -#define KEY(node) (node->key) -#define VALUE(node) (node->value) -#define LEFT_NODE(node) (node->link[LEFT]) -#define RIGHT_NODE(node) (node->link[RIGHT]) -#define LINK(node, dir) (node->link[dir]) -#define XDATA(node) (node->xdata) -#define RED(node) (node->xdata) -#define BALANCE(node) (node->xdata) - -static node_t * -ct_new_node(PyObject *key, PyObject *value, int xdata) -{ - node_t *new_node = PyMem_Malloc(sizeof(node_t)); - if (new_node != NULL) { - KEY(new_node) = key; - Py_INCREF(key); - VALUE(new_node) = value; - Py_INCREF(value); - LEFT_NODE(new_node) = NULL; - RIGHT_NODE(new_node) = NULL; - XDATA(new_node) = xdata; - } - return new_node; -} - -static void -ct_delete_node(node_t *node) -{ - if (node != NULL) { - Py_XDECREF(KEY(node)); - Py_XDECREF(VALUE(node)); - LEFT_NODE(node) = NULL; - RIGHT_NODE(node) = NULL; - PyMem_Free(node); - } -} - -extern void -ct_delete_tree(node_t *root) -{ - if (root == NULL) - return; - if (LEFT_NODE(root) != NULL) { - ct_delete_tree(LEFT_NODE(root)); - } - if (RIGHT_NODE(root) != NULL) { - ct_delete_tree(RIGHT_NODE(root)); - } - ct_delete_node(root); -} - -static void -ct_swap_data(node_t *node1, node_t *node2) -{ - PyObject *tmp; - tmp = KEY(node1); - KEY(node1) = KEY(node2); - KEY(node2) = tmp; - tmp = VALUE(node1); - VALUE(node1) = VALUE(node2); - VALUE(node2) = tmp; -} - -int -ct_compare(PyObject *key1, PyObject *key2) -{ - int res; - - res = PyObject_RichCompareBool(key1, key2, Py_LT); - if (res > 0) - return -1; - else if (res < 0) { - PyErr_SetString(PyExc_TypeError, "invalid type for key"); - return 0; - } - /* second compare: - +1 if key1 > key2 - 0 if not -> equal - -1 means error, if error, it should happend at the first compare - */ - return PyObject_RichCompareBool(key1, key2, Py_GT); -} - -extern node_t * -ct_find_node(node_t *root, PyObject *key) -{ - int res; - while (root != NULL) { - res = ct_compare(key, KEY(root)); - if (res == 0) /* key found */ - return root; - else { - root = LINK(root, (res > 0)); - } - } - return NULL; /* key not found */ -} - -extern PyObject * -ct_get_item(node_t *root, PyObject *key) -{ - node_t *node; - PyObject *tuple; - - node = ct_find_node(root, key); - if (node != NULL) { - tuple = PyTuple_New(2); - PyTuple_SET_ITEM(tuple, 0, KEY(node)); - PyTuple_SET_ITEM(tuple, 1, VALUE(node)); - return tuple; - } - Py_RETURN_NONE; -} - -extern node_t * -ct_max_node(node_t *root) -/* get node with largest key */ -{ - if (root == NULL) - return NULL; - while (RIGHT_NODE(root) != NULL) - root = RIGHT_NODE(root); - return root; -} - -extern node_t * -ct_min_node(node_t *root) -// get node with smallest key -{ - if (root == NULL) - return NULL; - while (LEFT_NODE(root) != NULL) - root = LEFT_NODE(root); - return root; -} - -extern int -ct_bintree_remove(node_t **rootaddr, PyObject *key) -/* attention: rootaddr is the address of the root pointer */ -{ - node_t *node, *parent, *replacement; - int direction, cmp_res, down_dir; - - node = *rootaddr; - - if (node == NULL) - return 0; /* root is NULL */ - parent = NULL; - direction = 0; - - while (1) { - cmp_res = ct_compare(key, KEY(node)); - if (cmp_res == 0) /* key found, remove node */ - { - if ((LEFT_NODE(node) != NULL) && (RIGHT_NODE(node) != NULL)) { - /* find replacement node: smallest key in right-subtree */ - parent = node; - direction = RIGHT; - replacement = RIGHT_NODE(node); - while (LEFT_NODE(replacement) != NULL) { - parent = replacement; - direction = LEFT; - replacement = LEFT_NODE(replacement); - } - LINK(parent, direction) = RIGHT_NODE(replacement); - /* swap places */ - ct_swap_data(node, replacement); - node = replacement; /* delete replacement node */ - } - else { - down_dir = (LEFT_NODE(node) == NULL) ? RIGHT : LEFT; - if (parent == NULL) /* root */ - { - *rootaddr = LINK(node, down_dir); - } - else { - LINK(parent, direction) = LINK(node, down_dir); - } - } - ct_delete_node(node); - return 1; /* remove was success full */ - } - else { - direction = (cmp_res < 0) ? LEFT : RIGHT; - parent = node; - node = LINK(node, direction); - if (node == NULL) - return 0; /* error key not found */ - } - } -} - -extern int -ct_bintree_insert(node_t **rootaddr, PyObject *key, PyObject *value) -/* attention: rootaddr is the address of the root pointer */ -{ - node_t *parent, *node; - int direction, cval; - node = *rootaddr; - if (node == NULL) { - node = ct_new_node(key, value, 0); /* new node is also the root */ - if (node == NULL) - return -1; /* got no memory */ - *rootaddr = node; - } - else { - direction = LEFT; - parent = NULL; - while (1) { - if (node == NULL) { - node = ct_new_node(key, value, 0); - if (node == NULL) - return -1; /* get no memory */ - LINK(parent, direction) = node; - return 1; - } - cval = ct_compare(key, KEY(node)); - if (cval == 0) { - /* key exists, replace value object */ - Py_XDECREF(VALUE(node)); /* release old value object */ - VALUE(node) = value; /* set new value object */ - Py_INCREF(value); /* take new value object */ - return 0; - } - else { - parent = node; - direction = (cval < 0) ? LEFT : RIGHT; - node = LINK(node, direction); - } - } - } - return 1; -} - -static int -is_red (node_t *node) -{ - return (node != NULL) && (RED(node) == 1); -} - -#define rb_new_node(key, value) ct_new_node(key, value, 1) - -static node_t * -rb_single(node_t *root, int dir) -{ - node_t *save = root->link[!dir]; - - root->link[!dir] = save->link[dir]; - save->link[dir] = root; - - RED(root) = 1; - RED(save) = 0; - return save; -} - -static node_t * -rb_double(node_t *root, int dir) -{ - root->link[!dir] = rb_single(root->link[!dir], !dir); - return rb_single(root, dir); -} - -#define rb_new_node(key, value) ct_new_node(key, value, 1) - -extern int -rb_insert(node_t **rootaddr, PyObject *key, PyObject *value) -{ - node_t *root = *rootaddr; - - if (root == NULL) { - /* - We have an empty tree; attach the - new node directly to the root - */ - root = rb_new_node(key, value); - if (root == NULL) - return -1; // got no memory - } - else { - node_t head; /* False tree root */ - node_t *g, *t; /* Grandparent & parent */ - node_t *p, *q; /* Iterator & parent */ - int dir = 0; - int last = 0; - int new_node = 0; - - /* Set up our helpers */ - t = &head; - g = NULL; - p = NULL; - RIGHT_NODE(t) = root; - LEFT_NODE(t) = NULL; - q = RIGHT_NODE(t); - - /* Search down the tree for a place to insert */ - for (;;) { - int cmp_res; - if (q == NULL) { - /* Insert a new node at the first null link */ - q = rb_new_node(key, value); - p->link[dir] = q; - new_node = 1; - if (q == NULL) - return -1; // get no memory - } - else if (is_red(q->link[0]) && is_red(q->link[1])) { - /* Simple red violation: color flip */ - RED(q) = 1; - RED(q->link[0]) = 0; - RED(q->link[1]) = 0; - } - - if (is_red(q) && is_red(p)) { - /* Hard red violation: rotations necessary */ - int dir2 = (t->link[1] == g); - - if (q == p->link[last]) - t->link[dir2] = rb_single(g, !last); - else - t->link[dir2] = rb_double(g, !last); - } - - /* Stop working if we inserted a new node. */ - if (new_node) - break; - - cmp_res = ct_compare(KEY(q), key); - if (cmp_res == 0) { /* key exists? */ - Py_XDECREF(VALUE(q)); /* release old value object */ - VALUE(q) = value; /* set new value object */ - Py_INCREF(value); /* take new value object */ - return 0; - } - last = dir; - dir = (cmp_res < 0); - - /* Move the helpers down */ - if (g != NULL) - t = g; - - g = p; - p = q; - q = q->link[dir]; - } - /* Update the root (it may be different) */ - root = head.link[1]; - } - - /* Make the root black for simplified logic */ - RED(root) = 0; - (*rootaddr) = root; - return 1; -} - -extern int -rb_remove(node_t **rootaddr, PyObject *key) -{ - node_t *root = *rootaddr; - - node_t head = { { NULL } }; /* False tree root */ - node_t *q, *p, *g; /* Helpers */ - node_t *f = NULL; /* Found item */ - int dir = 1; - - if (root == NULL) - return 0; - - /* Set up our helpers */ - q = &head; - g = p = NULL; - RIGHT_NODE(q) = root; - - /* - Search and push a red node down - to fix red violations as we go - */ - while (q->link[dir] != NULL) { - int last = dir; - int cmp_res; - - /* Move the helpers down */ - g = p, p = q; - q = q->link[dir]; - - cmp_res = ct_compare(KEY(q), key); - - dir = cmp_res < 0; - - /* - Save the node with matching data and keep - going; we'll do removal tasks at the end - */ - if (cmp_res == 0) - f = q; - - /* Push the red node down with rotations and color flips */ - if (!is_red(q) && !is_red(q->link[dir])) { - if (is_red(q->link[!dir])) - p = p->link[last] = rb_single(q, dir); - else if (!is_red(q->link[!dir])) { - node_t *s = p->link[!last]; - - if (s != NULL) { - if (!is_red(s->link[!last]) && - !is_red(s->link[last])) { - /* Color flip */ - RED(p) = 0; - RED(s) = 1; - RED(q) = 1; - } - else { - int dir2 = g->link[1] == p; - - if (is_red(s->link[last])) - g->link[dir2] = rb_double(p, last); - else if (is_red(s->link[!last])) - g->link[dir2] = rb_single(p, last); - - /* Ensure correct coloring */ - RED(q) = RED(g->link[dir2]) = 1; - RED(g->link[dir2]->link[0]) = 0; - RED(g->link[dir2]->link[1]) = 0; - } - } - } - } - } - - /* Replace and remove the saved node */ - if (f != NULL) { - ct_swap_data(f, q); - p->link[p->link[1] == q] = q->link[q->link[0] == NULL]; - ct_delete_node(q); - } - - /* Update the root (it may be different) */ - root = head.link[1]; - - /* Make the root black for simplified logic */ - if (root != NULL) - RED(root) = 0; - *rootaddr = root; - return (f != NULL); -} - -#define avl_new_node(key, value) ct_new_node(key, value, 0) -#define height(p) ((p) == NULL ? -1 : (p)->xdata) -#define avl_max(a, b) ((a) > (b) ? (a) : (b)) - -static node_t * -avl_single(node_t *root, int dir) -{ - node_t *save = root->link[!dir]; - int rlh, rrh, slh; - - /* Rotate */ - root->link[!dir] = save->link[dir]; - save->link[dir] = root; - - /* Update balance factors */ - rlh = height(root->link[0]); - rrh = height(root->link[1]); - slh = height(save->link[!dir]); - - BALANCE(root) = avl_max(rlh, rrh) + 1; - BALANCE(save) = avl_max(slh, BALANCE(root)) + 1; - - return save; -} - -static node_t * -avl_double(node_t *root, int dir) -{ - root->link[!dir] = avl_single(root->link[!dir], !dir); - return avl_single(root, dir); -} - -extern int -avl_insert(node_t **rootaddr, PyObject *key, PyObject *value) -{ - node_t *root = *rootaddr; - - if (root == NULL) { - root = avl_new_node(key, value); - if (root == NULL) - return -1; // got no memory - } - else { - node_t *it, *up[32]; - int upd[32], top = 0; - int done = 0; - int cmp_res; - - it = root; - /* Search for an empty link, save the path */ - for (;;) { - /* Push direction and node onto stack */ - cmp_res = ct_compare(KEY(it), key); - if (cmp_res == 0) { - Py_XDECREF(VALUE(it)); // release old value object - VALUE(it) = value; // set new value object - Py_INCREF(value); // take new value object - return 0; - } - // upd[top] = it->data < data; - upd[top] = (cmp_res < 0); - up[top++] = it; - - if (it->link[upd[top - 1]] == NULL) - break; - it = it->link[upd[top - 1]]; - } - - /* Insert a new node at the bottom of the tree */ - it->link[upd[top - 1]] = avl_new_node(key, value); - if (it->link[upd[top - 1]] == NULL) - return -1; // got no memory - - /* Walk back up the search path */ - while (--top >= 0 && !done) { - // int dir = (cmp_res < 0); - int lh, rh, max; - - cmp_res = ct_compare(KEY(up[top]), key); - - lh = height(up[top]->link[upd[top]]); - rh = height(up[top]->link[!upd[top]]); - - /* Terminate or rebalance as necessary */ - if (lh - rh == 0) - done = 1; - if (lh - rh >= 2) { - node_t *a = up[top]->link[upd[top]]->link[upd[top]]; - node_t *b = up[top]->link[upd[top]]->link[!upd[top]]; - - if (height( a ) >= height( b )) - up[top] = avl_single(up[top], !upd[top]); - else - up[top] = avl_double(up[top], !upd[top]); - - /* Fix parent */ - if (top != 0) - up[top - 1]->link[upd[top - 1]] = up[top]; - else - root = up[0]; - done = 1; - } - /* Update balance factors */ - lh = height(up[top]->link[upd[top]]); - rh = height(up[top]->link[!upd[top]]); - max = avl_max(lh, rh); - BALANCE(up[top]) = max + 1; - } - } - (*rootaddr) = root; - return 1; -} - -extern int -avl_remove(node_t **rootaddr, PyObject *key) -{ - node_t *root = *rootaddr; - int cmp_res; - - if (root != NULL) { - node_t *it, *up[32]; - int upd[32], top = 0; - - it = root; - for (;;) { - /* Terminate if not found */ - if (it == NULL) - return 0; - cmp_res = ct_compare(KEY(it), key); - if (cmp_res == 0) - break; - - /* Push direction and node onto stack */ - upd[top] = (cmp_res < 0); - up[top++] = it; - it = it->link[upd[top - 1]]; - } - - /* Remove the node */ - if (it->link[0] == NULL || - it->link[1] == NULL) { - /* Which child is not null? */ - int dir = it->link[0] == NULL; - - /* Fix parent */ - if (top != 0) - up[top - 1]->link[upd[top - 1]] = it->link[dir]; - else - root = it->link[dir]; - - ct_delete_node(it); - } - else { - /* Find the inorder successor */ - node_t *heir = it->link[1]; - - /* Save the path */ - upd[top] = 1; - up[top++] = it; - - while ( heir->link[0] != NULL ) { - upd[top] = 0; - up[top++] = heir; - heir = heir->link[0]; - } - /* Swap data */ - ct_swap_data(it, heir); - /* Unlink successor and fix parent */ - up[top - 1]->link[up[top - 1] == it] = heir->link[1]; - ct_delete_node(heir); - } - - /* Walk back up the search path */ - while (--top >= 0) { - int lh = height(up[top]->link[upd[top]]); - int rh = height(up[top]->link[!upd[top]]); - int max = avl_max(lh, rh); - - /* Update balance factors */ - BALANCE(up[top]) = max + 1; - - /* Terminate or rebalance as necessary */ - if (lh - rh == -1) - break; - if (lh - rh <= -2) { - node_t *a = up[top]->link[!upd[top]]->link[upd[top]]; - node_t *b = up[top]->link[!upd[top]]->link[!upd[top]]; - - if (height(a) <= height(b)) - up[top] = avl_single(up[top], upd[top]); - else - up[top] = avl_double(up[top], upd[top]); - - /* Fix parent */ - if (top != 0) - up[top - 1]->link[upd[top - 1]] = up[top]; - else - root = up[0]; - } - } - } - (*rootaddr) = root; - return 1; -} - -extern node_t * -ct_succ_node(node_t *root, PyObject *key) -{ - node_t *succ = NULL; - node_t *node = root; - int cval; - - while (node != NULL) { - cval = ct_compare(key, KEY(node)); - if (cval == 0) - break; - else if (cval < 0) { - if ((succ == NULL) || - (ct_compare(KEY(node), KEY(succ)) < 0)) - succ = node; - node = LEFT_NODE(node); - } else - node = RIGHT_NODE(node); - } - if (node == NULL) - return NULL; - /* found node of key */ - if (RIGHT_NODE(node) != NULL) { - /* find smallest node of right subtree */ - node = RIGHT_NODE(node); - while (LEFT_NODE(node) != NULL) - node = LEFT_NODE(node); - if (succ == NULL) - succ = node; - else if (ct_compare(KEY(node), KEY(succ)) < 0) - succ = node; - } - return succ; -} - -extern node_t * -ct_prev_node(node_t *root, PyObject *key) -{ - node_t *prev = NULL; - node_t *node = root; - int cval; - - while (node != NULL) { - cval = ct_compare(key, KEY(node)); - if (cval == 0) - break; - else if (cval < 0) - node = LEFT_NODE(node); - else { - if ((prev == NULL) || (ct_compare(KEY(node), KEY(prev)) > 0)) - prev = node; - node = RIGHT_NODE(node); - } - } - if (node == NULL) /* stay at dead end (None) */ - return NULL; - /* found node of key */ - if (LEFT_NODE(node) != NULL) { - /* find biggest node of left subtree */ - node = LEFT_NODE(node); - while (RIGHT_NODE(node) != NULL) - node = RIGHT_NODE(node); - if (prev == NULL) - prev = node; - else if (ct_compare(KEY(node), KEY(prev)) > 0) - prev = node; - } - return prev; -} - -extern node_t * -ct_floor_node(node_t *root, PyObject *key) -{ - node_t *prev = NULL; - node_t *node = root; - int cval; - - while (node != NULL) { - cval = ct_compare(key, KEY(node)); - if (cval == 0) - return node; - else if (cval < 0) - node = LEFT_NODE(node); - else { - if ((prev == NULL) || (ct_compare(KEY(node), KEY(prev)) > 0)) - prev = node; - node = RIGHT_NODE(node); - } - } - return prev; -} - -extern node_t * -ct_ceiling_node(node_t *root, PyObject *key) -{ - node_t *succ = NULL; - node_t *node = root; - int cval; - - while (node != NULL) { - cval = ct_compare(key, KEY(node)); - if (cval == 0) - return node; - else if (cval < 0) { - if ((succ == NULL) || - (ct_compare(KEY(node), KEY(succ)) < 0)) - succ = node; - node = LEFT_NODE(node); - } else - node = RIGHT_NODE(node); - } - return succ; -} - -extern int -ct_index_of(node_t *root, PyObject *key) -/* -get index of item <key>, returns -1 if key not found. -*/ -{ - node_t *node = root; - int index = 0; - int go_down = 1; - node_stack_t *stack; - stack = stack_init(32); - - for (;;) { - if ((LEFT_NODE(node) != NULL) && go_down) { - stack_push(stack, node); - node = LEFT_NODE(node); - } - else { - if (ct_compare(KEY(node), key) == 0) { - stack_delete(stack); - return index; - } - index++; - if (RIGHT_NODE(node) != NULL) { - node = RIGHT_NODE(node); - go_down = 1; - } - else { - if (stack_is_empty(stack)) { - stack_delete(stack); - return -1; - } - node = stack_pop(stack); - go_down = 0; - } - } - } -} - -extern node_t * -ct_node_at(node_t *root, int index) -{ -/* -root -- root node of tree -index -- index of wanted node - -return NULL if index out of range -*/ - node_t *node = root; - int counter = 0; - int go_down = 1; - node_stack_t *stack; - - if (index < 0) return NULL; - - stack = stack_init(32); - - for(;;) { - if ((LEFT_NODE(node) != NULL) && go_down) { - stack_push(stack, node); - node = LEFT_NODE(node); - } - else { - if (counter == index) { - /* reached wanted index */ - stack_delete(stack); - return node; - } - counter++; - if (RIGHT_NODE(node) != NULL) { - node = RIGHT_NODE(node); - go_down = 1; - } - else { - if (stack_is_empty(stack)) { /* index out of range */ - stack_delete(stack); - return NULL; - } - node = stack_pop(stack); - go_down = 0; - } - } - } -}
diff --git a/third_party/bintrees/bintrees/ctrees.h b/third_party/bintrees/bintrees/ctrees.h deleted file mode 100644 index 17afe720..0000000 --- a/third_party/bintrees/bintrees/ctrees.h +++ /dev/null
@@ -1,51 +0,0 @@ -/* - * ctrees.h - * - * Author: mozman - * Copyright (c) 2010-2013 by Manfred Moitzi - * License: MIT-License - */ - -#ifndef __CTREES_H -#define __CTREES_H - -#include <Python.h> - -typedef struct tree_node node_t; - -struct tree_node { - node_t *link[2]; - PyObject *key; - PyObject *value; - int xdata; -}; - -typedef node_t* nodeptr; - -/* common binary tree functions */ -void ct_delete_tree(node_t *root); -int ct_compare(PyObject *key1, PyObject *key2); -PyObject *ct_get_item(node_t *root, PyObject *key); -node_t *ct_find_node(node_t *root, PyObject *key); -node_t *ct_succ_node(node_t *root, PyObject *key); -node_t *ct_prev_node(node_t *root, PyObject *key); -node_t *ct_max_node(node_t *root); -node_t *ct_min_node(node_t *root); -node_t *ct_floor_node(node_t *root, PyObject *key); -node_t *ct_ceiling_node(node_t *root, PyObject *key); -int ct_index_of(node_t *root, PyObject *key); -node_t *ct_node_at(node_t *root, int index); - -/* unbalanced binary tree */ -int ct_bintree_insert(node_t **root, PyObject *key, PyObject *value); -int ct_bintree_remove(node_t **root, PyObject *key); - -/* avl-tree functions */ -int avl_insert(node_t **root, PyObject *key, PyObject *value); -int avl_remove(node_t **root, PyObject *key); - -/* rb-tree functions */ -int rb_insert(node_t **root, PyObject *key, PyObject *value); -int rb_remove(node_t **root, PyObject *key); - -#endif
diff --git a/third_party/bintrees/bintrees/ctrees.pxd b/third_party/bintrees/bintrees/ctrees.pxd deleted file mode 100644 index c96a2ca..0000000 --- a/third_party/bintrees/bintrees/ctrees.pxd +++ /dev/null
@@ -1,38 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Created: 08.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -cdef extern from "ctrees.h": - ctypedef struct PyObject: - pass - - ctypedef struct node_t: - node_t *link[2] - PyObject *key - PyObject *value - - int ct_compare(object key1, object key2) - void ct_delete_tree(node_t *root) - node_t *ct_find_node(node_t *root, object key) - PyObject *ct_get_item(node_t *root, object key) - node_t *ct_max_node(node_t *root) - node_t *ct_min_node(node_t *root) - node_t *ct_succ_node(node_t *root, object key) - node_t *ct_prev_node(node_t *root, object key) - node_t *ct_floor_node(node_t *root, object key) - node_t *ct_ceiling_node(node_t *root, object key) - int ct_index_of(node_t *root, object key) - node_t *ct_node_at(node_t *root, int index) - - # binary-tree functions - int ct_bintree_insert(node_t **root, object key, object value) - int ct_bintree_remove(node_t **root, object key) - # avl-tree functions - int avl_insert(node_t **root, object key, object value) - int avl_remove(node_t **root, object key) - # rb-tree functions - int rb_insert(node_t **root, object key, object value) - int rb_remove(node_t **root, object key) \ No newline at end of file
diff --git a/third_party/bintrees/bintrees/cwalker.c b/third_party/bintrees/bintrees/cwalker.c deleted file mode 100644 index 0779b4d..0000000 --- a/third_party/bintrees/bintrees/cwalker.c +++ /dev/null
@@ -1,3799 +0,0 @@ -/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. -#else -#include <stddef.h> /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef Py_HUGE_VAL - #define Py_HUGE_VAL HUGE_VAL -#endif -#ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 -#else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define CYTHON_FORMAT_SSIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ - (PyErr_Format(PyExc_TypeError, \ - "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ - (PyObject*)0)) - #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \ - !PyComplex_Check(o)) - #define PyIndex_Check __Pyx_PyIndex_Check - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" - #define CYTHON_FORMAT_SSIZE_T "z" - #define __Pyx_PyIndex_Check PyIndex_Check -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) - #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ - 0 : _PyUnicode_Ready((PyObject *)(op))) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) - #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) -#else - #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_READY(op) (0) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif -#ifndef PySet_CheckExact - #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) -#if PY_MAJOR_VERSION >= 3 - #define PyIntObject PyLongObject - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBoolObject PyLongObject -#endif -#if PY_VERSION_HEX < 0x03020000 - typedef long Py_hash_t; - #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong -#else - #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t -#endif -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#ifndef __PYX_EXTERN_C - #ifdef __cplusplus - #define __PYX_EXTERN_C extern "C" - #else - #define __PYX_EXTERN_C extern - #endif -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include <math.h> -#define __PYX_HAVE__bintrees__cwalker -#define __PYX_HAVE_API__bintrees__cwalker -#include "ctrees.h" -#include "stack.h" -#ifdef _OPENMP -#include <omp.h> -#endif /* _OPENMP */ - -#ifdef PYREX_WITHOUT_ASSERTIONS -#define CYTHON_WITHOUT_ASSERTIONS -#endif - - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#if CYTHON_COMPILING_IN_CPYTHON -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) -#else -#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) -#endif -#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) - -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ - #define likely(x) (x) - #define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -static const char *__pyx_f[] = { - "cwalker.pyx", -}; - -/*--- Type declarations ---*/ -struct __pyx_obj_8bintrees_7cwalker_cWalker; - -/* "bintrees\cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ -struct __pyx_obj_8bintrees_7cwalker_cWalker { - PyObject_HEAD - struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab; - node_t *node; - node_t *root; - node_stack_t *stack; -}; - - - -/* "bintrees\cwalker.pyx":14 - * from ctrees cimport * - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * def __cinit__(self): - * self.root = NULL - */ - -struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker { - void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *); - PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); -}; -static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker; -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ - #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; -#ifdef WITH_THREAD - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - if (acquire_gil) { \ - PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - } -#else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) -#endif - #define __Pyx_RefNannyFinishContext() \ - __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) - #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) - #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) -#else - #define __Pyx_RefNannyDeclarations - #define __Pyx_RefNannySetupContext(name, acquire_gil) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XINCREF(r) Py_XINCREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) - #define __Pyx_XGOTREF(r) - #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) -#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename); /*proto*/ - -static int __Pyx_check_binary_version(void); - -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ - -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - - -/* Module declarations from 'bintrees.ctrees' */ - -/* Module declarations from 'bintrees.stack' */ - -/* Module declarations from 'bintrees.cwalker' */ -static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0; -#define __Pyx_MODULE_NAME "bintrees.cwalker" -int __pyx_module_is_main_bintrees__cwalker = 0; - -/* Implementation of 'bintrees.cwalker' */ -static PyObject *__pyx_builtin_property; -static PyObject *__pyx_builtin_IndexError; -static PyObject *__pyx_builtin_KeyError; -static int __pyx_pf_8bintrees_7cwalker_7cWalker___cinit__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static void __pyx_pf_8bintrees_7cwalker_7cWalker_2__dealloc__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_4reset(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_6key(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_8value(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_10item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_12is_valid(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_14goto(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_16push(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_18pop(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_20stack_is_empty(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_22goto_leaf(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_24has_child(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_26down(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_28go_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_30go_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_32has_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_34has_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_36succ_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_38prev_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_40floor_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_42ceiling_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static char __pyx_k_1[] = "pop(): stack is empty"; -static char __pyx_k__key[] = "key"; -static char __pyx_k__pop[] = "pop"; -static char __pyx_k__item[] = "item"; -static char __pyx_k__push[] = "push"; -static char __pyx_k__reset[] = "reset"; -static char __pyx_k__value[] = "value"; -static char __pyx_k__KeyError[] = "KeyError"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__is_valid[] = "is_valid"; -static char __pyx_k__property[] = "property"; -static char __pyx_k__IndexError[] = "IndexError"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_n_s__IndexError; -static PyObject *__pyx_n_s__KeyError; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__is_valid; -static PyObject *__pyx_n_s__item; -static PyObject *__pyx_n_s__key; -static PyObject *__pyx_n_s__pop; -static PyObject *__pyx_n_s__property; -static PyObject *__pyx_n_s__push; -static PyObject *__pyx_n_s__reset; -static PyObject *__pyx_n_s__value; -static PyObject *__pyx_k_tuple_2; - -/* Python wrapper */ -static int __pyx_pw_8bintrees_7cwalker_7cWalker_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8bintrees_7cwalker_7cWalker_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker___cinit__(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":15 - * - * cdef class cWalker: - * def __cinit__(self): # <<<<<<<<<<<<<< - * self.root = NULL - * self.node = NULL - */ - -static int __pyx_pf_8bintrees_7cwalker_7cWalker___cinit__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "bintrees\cwalker.pyx":16 - * cdef class cWalker: - * def __cinit__(self): - * self.root = NULL # <<<<<<<<<<<<<< - * self.node = NULL - * self.stack = stack_init(MAXSTACK) - */ - __pyx_v_self->root = NULL; - - /* "bintrees\cwalker.pyx":17 - * def __cinit__(self): - * self.root = NULL - * self.node = NULL # <<<<<<<<<<<<<< - * self.stack = stack_init(MAXSTACK) - * - */ - __pyx_v_self->node = NULL; - - /* "bintrees\cwalker.pyx":18 - * self.root = NULL - * self.node = NULL - * self.stack = stack_init(MAXSTACK) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->stack = stack_init(32); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8bintrees_7cwalker_7cWalker_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8bintrees_7cwalker_7cWalker_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8bintrees_7cwalker_7cWalker_2__dealloc__(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "bintrees\cwalker.pyx":20 - * self.stack = stack_init(MAXSTACK) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * stack_delete(self.stack) - * - */ - -static void __pyx_pf_8bintrees_7cwalker_7cWalker_2__dealloc__(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "bintrees\cwalker.pyx":21 - * - * def __dealloc__(self): - * stack_delete(self.stack) # <<<<<<<<<<<<<< - * - * cdef void set_tree(self, node_t *root): - */ - stack_delete(__pyx_v_self->stack); - - __Pyx_RefNannyFinishContext(); -} - -/* "bintrees\cwalker.pyx":23 - * stack_delete(self.stack) - * - * cdef void set_tree(self, node_t *root): # <<<<<<<<<<<<<< - * self.root = root - * self.reset() - */ - -static void __pyx_f_8bintrees_7cwalker_7cWalker_set_tree(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, node_t *__pyx_v_root) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("set_tree", 0); - - /* "bintrees\cwalker.pyx":24 - * - * cdef void set_tree(self, node_t *root): - * self.root = root # <<<<<<<<<<<<<< - * self.reset() - * - */ - __pyx_v_self->root = __pyx_v_root; - - /* "bintrees\cwalker.pyx":25 - * cdef void set_tree(self, node_t *root): - * self.root = root - * self.reset() # <<<<<<<<<<<<<< - * - * cpdef reset(self): - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->reset(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_WriteUnraisable("bintrees.cwalker.cWalker.set_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* "bintrees\cwalker.pyx":27 - * self.reset() - * - * cpdef reset(self): # <<<<<<<<<<<<<< - * stack_reset(self.stack) - * self.node = self.root - */ - -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_5reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_f_8bintrees_7cwalker_7cWalker_reset(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_skip_dispatch) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - node_t *__pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("reset", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overriden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_5reset)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "bintrees\cwalker.pyx":28 - * - * cpdef reset(self): - * stack_reset(self.stack) # <<<<<<<<<<<<<< - * self.node = self.root - * - */ - stack_reset(__pyx_v_self->stack); - - /* "bintrees\cwalker.pyx":29 - * cpdef reset(self): - * stack_reset(self.stack) - * self.node = self.root # <<<<<<<<<<<<<< - * - * @property - */ - __pyx_t_3 = __pyx_v_self->root; - __pyx_v_self->node = __pyx_t_3; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.reset", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_5reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_5reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("reset (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_4reset(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":27 - * self.reset() - * - * cpdef reset(self): # <<<<<<<<<<<<<< - * stack_reset(self.stack) - * self.node = self.root - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_4reset(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("reset", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->reset(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.reset", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_7key(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_7key(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("key (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_6key(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":32 - * - * @property - * def key(self): # <<<<<<<<<<<<<< - * return <object> self.node.key - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_6key(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("key", 0); - - /* "bintrees\cwalker.pyx":33 - * @property - * def key(self): - * return <object> self.node.key # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key)); - __pyx_r = ((PyObject *)__pyx_v_self->node->key); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_9value(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_9value(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("value (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_8value(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":36 - * - * @property - * def value(self): # <<<<<<<<<<<<<< - * return <object> self.node.value - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_8value(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("value", 0); - - /* "bintrees\cwalker.pyx":37 - * @property - * def value(self): - * return <object> self.node.value # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value)); - __pyx_r = ((PyObject *)__pyx_v_self->node->value); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_11item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_11item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_10item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":40 - * - * @property - * def item(self): # <<<<<<<<<<<<<< - * return (<object>self.node.key, <object>self.node.value) - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_10item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("item", 0); - - /* "bintrees\cwalker.pyx":41 - * @property - * def item(self): - * return (<object>self.node.key, <object>self.node.value) # <<<<<<<<<<<<<< - * - * @property - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self->node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value)); - __pyx_r = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_13is_valid(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_13is_valid(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("is_valid (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_12is_valid(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":44 - * - * @property - * def is_valid(self): # <<<<<<<<<<<<<< - * return self.node != NULL - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_12is_valid(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("is_valid", 0); - - /* "bintrees\cwalker.pyx":45 - * @property - * def is_valid(self): - * return self.node != NULL # <<<<<<<<<<<<<< - * - * def goto(self, key): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->node != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.is_valid", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_15goto(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_15goto(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("goto (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_14goto(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":47 - * return self.node != NULL - * - * def goto(self, key): # <<<<<<<<<<<<<< - * cdef int cval - * self.node = self.root - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_14goto(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_v_cval; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - node_t *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("goto", 0); - - /* "bintrees\cwalker.pyx":49 - * def goto(self, key): - * cdef int cval - * self.node = self.root # <<<<<<<<<<<<<< - * while self.node != NULL: - * cval = ct_compare(key, <object> self.node.key) - */ - __pyx_t_1 = __pyx_v_self->root; - __pyx_v_self->node = __pyx_t_1; - - /* "bintrees\cwalker.pyx":50 - * cdef int cval - * self.node = self.root - * while self.node != NULL: # <<<<<<<<<<<<<< - * cval = ct_compare(key, <object> self.node.key) - * if cval == 0: - */ - while (1) { - __pyx_t_2 = (__pyx_v_self->node != NULL); - if (!__pyx_t_2) break; - - /* "bintrees\cwalker.pyx":51 - * self.node = self.root - * while self.node != NULL: - * cval = ct_compare(key, <object> self.node.key) # <<<<<<<<<<<<<< - * if cval == 0: - * return True - */ - __pyx_t_3 = ((PyObject *)__pyx_v_self->node->key); - __Pyx_INCREF(__pyx_t_3); - __pyx_v_cval = ct_compare(__pyx_v_key, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "bintrees\cwalker.pyx":52 - * while self.node != NULL: - * cval = ct_compare(key, <object> self.node.key) - * if cval == 0: # <<<<<<<<<<<<<< - * return True - * elif cval < 0: - */ - __pyx_t_2 = (__pyx_v_cval == 0); - if (__pyx_t_2) { - - /* "bintrees\cwalker.pyx":53 - * cval = ct_compare(key, <object> self.node.key) - * if cval == 0: - * return True # <<<<<<<<<<<<<< - * elif cval < 0: - * self.node = self.node.link[0] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - goto __pyx_L5; - } - - /* "bintrees\cwalker.pyx":54 - * if cval == 0: - * return True - * elif cval < 0: # <<<<<<<<<<<<<< - * self.node = self.node.link[0] - * else: - */ - __pyx_t_2 = (__pyx_v_cval < 0); - if (__pyx_t_2) { - - /* "bintrees\cwalker.pyx":55 - * return True - * elif cval < 0: - * self.node = self.node.link[0] # <<<<<<<<<<<<<< - * else: - * self.node = self.node.link[1] - */ - __pyx_v_self->node = (__pyx_v_self->node->link[0]); - goto __pyx_L5; - } - /*else*/ { - - /* "bintrees\cwalker.pyx":57 - * self.node = self.node.link[0] - * else: - * self.node = self.node.link[1] # <<<<<<<<<<<<<< - * return False - * - */ - __pyx_v_self->node = (__pyx_v_self->node->link[1]); - } - __pyx_L5:; - } - - /* "bintrees\cwalker.pyx":58 - * else: - * self.node = self.node.link[1] - * return False # <<<<<<<<<<<<<< - * - * cpdef push(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.goto", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":60 - * return False - * - * cpdef push(self): # <<<<<<<<<<<<<< - * stack_push(self.stack, self.node) - * - */ - -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_17push(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_f_8bintrees_7cwalker_7cWalker_push(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_skip_dispatch) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("push", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overriden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__push); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_17push)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "bintrees\cwalker.pyx":61 - * - * cpdef push(self): - * stack_push(self.stack, self.node) # <<<<<<<<<<<<<< - * - * cpdef pop(self): - */ - stack_push(__pyx_v_self->stack, __pyx_v_self->node); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.push", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_17push(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_17push(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("push (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_16push(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":60 - * return False - * - * cpdef push(self): # <<<<<<<<<<<<<< - * stack_push(self.stack, self.node) - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_16push(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("push", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->push(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.push", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":63 - * stack_push(self.stack, self.node) - * - * cpdef pop(self): # <<<<<<<<<<<<<< - * if stack_is_empty(self.stack) != 0: - * raise IndexError('pop(): stack is empty') - */ - -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_19pop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_f_8bintrees_7cwalker_7cWalker_pop(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_skip_dispatch) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("pop", 0); - /* Check if called by wrapper */ - if (unlikely(__pyx_skip_dispatch)) ; - /* Check if overriden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_19pop)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "bintrees\cwalker.pyx":64 - * - * cpdef pop(self): - * if stack_is_empty(self.stack) != 0: # <<<<<<<<<<<<<< - * raise IndexError('pop(): stack is empty') - * self.node = stack_pop(self.stack) - */ - __pyx_t_3 = (stack_is_empty(__pyx_v_self->stack) != 0); - if (__pyx_t_3) { - - /* "bintrees\cwalker.pyx":65 - * cpdef pop(self): - * if stack_is_empty(self.stack) != 0: - * raise IndexError('pop(): stack is empty') # <<<<<<<<<<<<<< - * self.node = stack_pop(self.stack) - * - */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\cwalker.pyx":66 - * if stack_is_empty(self.stack) != 0: - * raise IndexError('pop(): stack is empty') - * self.node = stack_pop(self.stack) # <<<<<<<<<<<<<< - * - * def stack_is_empty(self): - */ - __pyx_v_self->node = stack_pop(__pyx_v_self->stack); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_19pop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_19pop(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("pop (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_18pop(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":63 - * stack_push(self.stack, self.node) - * - * cpdef pop(self): # <<<<<<<<<<<<<< - * if stack_is_empty(self.stack) != 0: - * raise IndexError('pop(): stack is empty') - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_18pop(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("pop", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_self->__pyx_vtab)->pop(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.pop", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_21stack_is_empty(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_21stack_is_empty(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("stack_is_empty (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_20stack_is_empty(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":68 - * self.node = stack_pop(self.stack) - * - * def stack_is_empty(self): # <<<<<<<<<<<<<< - * return <bint> stack_is_empty(self.stack) - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_20stack_is_empty(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("stack_is_empty", 0); - - /* "bintrees\cwalker.pyx":69 - * - * def stack_is_empty(self): - * return <bint> stack_is_empty(self.stack) # <<<<<<<<<<<<<< - * - * def goto_leaf(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((int)stack_is_empty(__pyx_v_self->stack))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.stack_is_empty", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_23goto_leaf(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_7cwalker_7cWalker_22goto_leaf[] = " get a leaf node "; -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_23goto_leaf(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("goto_leaf (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_22goto_leaf(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":71 - * return <bint> stack_is_empty(self.stack) - * - * def goto_leaf(self): # <<<<<<<<<<<<<< - * """ get a leaf node """ - * while self.node != NULL: - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_22goto_leaf(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("goto_leaf", 0); - - /* "bintrees\cwalker.pyx":73 - * def goto_leaf(self): - * """ get a leaf node """ - * while self.node != NULL: # <<<<<<<<<<<<<< - * if self.node.link[0] != NULL: - * self.node = self.node.link[0] - */ - while (1) { - __pyx_t_1 = (__pyx_v_self->node != NULL); - if (!__pyx_t_1) break; - - /* "bintrees\cwalker.pyx":74 - * """ get a leaf node """ - * while self.node != NULL: - * if self.node.link[0] != NULL: # <<<<<<<<<<<<<< - * self.node = self.node.link[0] - * elif self.node.link[1] != NULL: - */ - __pyx_t_1 = ((__pyx_v_self->node->link[0]) != NULL); - if (__pyx_t_1) { - - /* "bintrees\cwalker.pyx":75 - * while self.node != NULL: - * if self.node.link[0] != NULL: - * self.node = self.node.link[0] # <<<<<<<<<<<<<< - * elif self.node.link[1] != NULL: - * self.node = self.node.link[1] - */ - __pyx_v_self->node = (__pyx_v_self->node->link[0]); - goto __pyx_L5; - } - - /* "bintrees\cwalker.pyx":76 - * if self.node.link[0] != NULL: - * self.node = self.node.link[0] - * elif self.node.link[1] != NULL: # <<<<<<<<<<<<<< - * self.node = self.node.link[1] - * else: - */ - __pyx_t_1 = ((__pyx_v_self->node->link[1]) != NULL); - if (__pyx_t_1) { - - /* "bintrees\cwalker.pyx":77 - * self.node = self.node.link[0] - * elif self.node.link[1] != NULL: - * self.node = self.node.link[1] # <<<<<<<<<<<<<< - * else: - * return - */ - __pyx_v_self->node = (__pyx_v_self->node->link[1]); - goto __pyx_L5; - } - /*else*/ { - - /* "bintrees\cwalker.pyx":79 - * self.node = self.node.link[1] - * else: - * return # <<<<<<<<<<<<<< - * - * def has_child(self, int direction): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - } - __pyx_L5:; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_25has_child(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_25has_child(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction) { - int __pyx_v_direction; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("has_child (wrapper)", 0); - assert(__pyx_arg_direction); { - __pyx_v_direction = __Pyx_PyInt_AsInt(__pyx_arg_direction); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_child", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_24has_child(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((int)__pyx_v_direction)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":81 - * return - * - * def has_child(self, int direction): # <<<<<<<<<<<<<< - * return self.node.link[direction] != NULL - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_24has_child(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("has_child", 0); - - /* "bintrees\cwalker.pyx":82 - * - * def has_child(self, int direction): - * return self.node.link[direction] != NULL # <<<<<<<<<<<<<< - * - * def down(self, int direction): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->node->link[__pyx_v_direction]) != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_child", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_27down(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_27down(PyObject *__pyx_v_self, PyObject *__pyx_arg_direction) { - int __pyx_v_direction; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("down (wrapper)", 0); - assert(__pyx_arg_direction); { - __pyx_v_direction = __Pyx_PyInt_AsInt(__pyx_arg_direction); if (unlikely((__pyx_v_direction == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.cwalker.cWalker.down", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_26down(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((int)__pyx_v_direction)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":84 - * return self.node.link[direction] != NULL - * - * def down(self, int direction): # <<<<<<<<<<<<<< - * self.node = self.node.link[direction] - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_26down(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, int __pyx_v_direction) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("down", 0); - - /* "bintrees\cwalker.pyx":85 - * - * def down(self, int direction): - * self.node = self.node.link[direction] # <<<<<<<<<<<<<< - * - * def go_left(self): - */ - __pyx_v_self->node = (__pyx_v_self->node->link[__pyx_v_direction]); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_29go_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_29go_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("go_left (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_28go_left(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":87 - * self.node = self.node.link[direction] - * - * def go_left(self): # <<<<<<<<<<<<<< - * self.node = self.node.link[0] - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_28go_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("go_left", 0); - - /* "bintrees\cwalker.pyx":88 - * - * def go_left(self): - * self.node = self.node.link[0] # <<<<<<<<<<<<<< - * - * def go_right(self): - */ - __pyx_v_self->node = (__pyx_v_self->node->link[0]); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_31go_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_31go_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("go_right (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_30go_right(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":90 - * self.node = self.node.link[0] - * - * def go_right(self): # <<<<<<<<<<<<<< - * self.node = self.node.link[1] - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_30go_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("go_right", 0); - - /* "bintrees\cwalker.pyx":91 - * - * def go_right(self): - * self.node = self.node.link[1] # <<<<<<<<<<<<<< - * - * def has_left(self): - */ - __pyx_v_self->node = (__pyx_v_self->node->link[1]); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_33has_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_33has_left(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("has_left (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_32has_left(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":93 - * self.node = self.node.link[1] - * - * def has_left(self): # <<<<<<<<<<<<<< - * return self.node.link[0] != NULL - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_32has_left(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("has_left", 0); - - /* "bintrees\cwalker.pyx":94 - * - * def has_left(self): - * return self.node.link[0] != NULL # <<<<<<<<<<<<<< - * - * def has_right(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->node->link[0]) != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_left", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_35has_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_35has_right(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("has_right (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_34has_right(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":96 - * return self.node.link[0] != NULL - * - * def has_right(self): # <<<<<<<<<<<<<< - * return self.node.link[1] != NULL - * - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_34has_right(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("has_right", 0); - - /* "bintrees\cwalker.pyx":97 - * - * def has_right(self): - * return self.node.link[1] != NULL # <<<<<<<<<<<<<< - * - * def succ_item(self, key): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->node->link[1]) != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.has_right", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_37succ_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static char __pyx_doc_8bintrees_7cwalker_7cWalker_36succ_item[] = " Get successor (k,v) pair of key, raises KeyError if key is max key\n or key does not exist.\n "; -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_37succ_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("succ_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_36succ_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":99 - * return self.node.link[1] != NULL - * - * def succ_item(self, key): # <<<<<<<<<<<<<< - * """ Get successor (k,v) pair of key, raises KeyError if key is max key - * or key does not exist. - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_36succ_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("succ_item", 0); - - /* "bintrees\cwalker.pyx":103 - * or key does not exist. - * """ - * self.node = ct_succ_node(self.root, key) # <<<<<<<<<<<<<< - * if self.node == NULL: # given key is biggest in tree - * raise KeyError(str(key)) - */ - __pyx_v_self->node = ct_succ_node(__pyx_v_self->root, __pyx_v_key); - - /* "bintrees\cwalker.pyx":104 - * """ - * self.node = ct_succ_node(self.root, key) - * if self.node == NULL: # given key is biggest in tree # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) - */ - __pyx_t_1 = (__pyx_v_self->node == NULL); - if (__pyx_t_1) { - - /* "bintrees\cwalker.pyx":105 - * self.node = ct_succ_node(self.root, key) - * if self.node == NULL: # given key is biggest in tree - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * return (<object> self.node.key, <object> self.node.value) - * - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\cwalker.pyx":106 - * if self.node == NULL: # given key is biggest in tree - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<< - * - * def prev_item(self, key): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value)); - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.succ_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_39prev_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static char __pyx_doc_8bintrees_7cwalker_7cWalker_38prev_item[] = " Get predecessor (k,v) pair of key, raises KeyError if key is min key\n or key does not exist.\n "; -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_39prev_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("prev_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_38prev_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":108 - * return (<object> self.node.key, <object> self.node.value) - * - * def prev_item(self, key): # <<<<<<<<<<<<<< - * """ Get predecessor (k,v) pair of key, raises KeyError if key is min key - * or key does not exist. - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_38prev_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("prev_item", 0); - - /* "bintrees\cwalker.pyx":112 - * or key does not exist. - * """ - * self.node = ct_prev_node(self.root, key) # <<<<<<<<<<<<<< - * if self.node == NULL: # given key is smallest in tree - * raise KeyError(str(key)) - */ - __pyx_v_self->node = ct_prev_node(__pyx_v_self->root, __pyx_v_key); - - /* "bintrees\cwalker.pyx":113 - * """ - * self.node = ct_prev_node(self.root, key) - * if self.node == NULL: # given key is smallest in tree # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) - */ - __pyx_t_1 = (__pyx_v_self->node == NULL); - if (__pyx_t_1) { - - /* "bintrees\cwalker.pyx":114 - * self.node = ct_prev_node(self.root, key) - * if self.node == NULL: # given key is smallest in tree - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * return (<object> self.node.key, <object> self.node.value) - * - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\cwalker.pyx":115 - * if self.node == NULL: # given key is smallest in tree - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<< - * - * def floor_item(self, key): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value)); - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.prev_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_41floor_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static char __pyx_doc_8bintrees_7cwalker_7cWalker_40floor_item[] = " Get the element (k,v) pair associated with the greatest key less\n than or equal to the given key, raises KeyError if there is no such key.\n "; -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_41floor_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("floor_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_40floor_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":117 - * return (<object> self.node.key, <object> self.node.value) - * - * def floor_item(self, key): # <<<<<<<<<<<<<< - * """ Get the element (k,v) pair associated with the greatest key less - * than or equal to the given key, raises KeyError if there is no such key. - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_40floor_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("floor_item", 0); - - /* "bintrees\cwalker.pyx":121 - * than or equal to the given key, raises KeyError if there is no such key. - * """ - * self.node = ct_floor_node(self.root, key) # <<<<<<<<<<<<<< - * if self.node == NULL: # given key is smaller than min-key in tree - * raise KeyError(str(key)) - */ - __pyx_v_self->node = ct_floor_node(__pyx_v_self->root, __pyx_v_key); - - /* "bintrees\cwalker.pyx":122 - * """ - * self.node = ct_floor_node(self.root, key) - * if self.node == NULL: # given key is smaller than min-key in tree # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) - */ - __pyx_t_1 = (__pyx_v_self->node == NULL); - if (__pyx_t_1) { - - /* "bintrees\cwalker.pyx":123 - * self.node = ct_floor_node(self.root, key) - * if self.node == NULL: # given key is smaller than min-key in tree - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * return (<object> self.node.key, <object> self.node.value) - * - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\cwalker.pyx":124 - * if self.node == NULL: # given key is smaller than min-key in tree - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<< - * - * def ceiling_item(self, key): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value)); - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.floor_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_43ceiling_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static char __pyx_doc_8bintrees_7cwalker_7cWalker_42ceiling_item[] = " Get the element (k,v) pair associated with the smallest key greater\n than or equal to the given key, raises KeyError if there is no such key.\n "; -static PyObject *__pyx_pw_8bintrees_7cwalker_7cWalker_43ceiling_item(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("ceiling_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7cwalker_7cWalker_42ceiling_item(((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\cwalker.pyx":126 - * return (<object> self.node.key, <object> self.node.value) - * - * def ceiling_item(self, key): # <<<<<<<<<<<<<< - * """ Get the element (k,v) pair associated with the smallest key greater - * than or equal to the given key, raises KeyError if there is no such key. - */ - -static PyObject *__pyx_pf_8bintrees_7cwalker_7cWalker_42ceiling_item(struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("ceiling_item", 0); - - /* "bintrees\cwalker.pyx":130 - * than or equal to the given key, raises KeyError if there is no such key. - * """ - * self.node = ct_ceiling_node(self.root, key) # <<<<<<<<<<<<<< - * if self.node == NULL: # given key is greater than max-key in tree - * raise KeyError(str(key)) - */ - __pyx_v_self->node = ct_ceiling_node(__pyx_v_self->root, __pyx_v_key); - - /* "bintrees\cwalker.pyx":131 - * """ - * self.node = ct_ceiling_node(self.root, key) - * if self.node == NULL: # given key is greater than max-key in tree # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) - */ - __pyx_t_1 = (__pyx_v_self->node == NULL); - if (__pyx_t_1) { - - /* "bintrees\cwalker.pyx":132 - * self.node = ct_ceiling_node(self.root, key) - * if self.node == NULL: # given key is greater than max-key in tree - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * return (<object> self.node.key, <object> self.node.value) - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\cwalker.pyx":133 - * if self.node == NULL: # given key is greater than max-key in tree - * raise KeyError(str(key)) - * return (<object> self.node.key, <object> self.node.value) # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->key)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->node->value)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_self->node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->node->value)); - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.cwalker.cWalker.ceiling_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker __pyx_vtable_8bintrees_7cwalker_cWalker; - -static PyObject *__pyx_tp_new_8bintrees_7cwalker_cWalker(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_8bintrees_7cwalker_cWalker *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)o); - p->__pyx_vtab = __pyx_vtabptr_8bintrees_7cwalker_cWalker; - if (__pyx_pw_8bintrees_7cwalker_7cWalker_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8bintrees_7cwalker_cWalker(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8bintrees_7cwalker_7cWalker_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_8bintrees_7cwalker_cWalker[] = { - {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_5reset, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("key"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_7key, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("value"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_9value, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_11item, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("is_valid"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_13is_valid, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("goto"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_15goto, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("push"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_17push, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("pop"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_19pop, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("stack_is_empty"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_21stack_is_empty, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("goto_leaf"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_23goto_leaf, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_22goto_leaf)}, - {__Pyx_NAMESTR("has_child"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_25has_child, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("down"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_27down, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("go_left"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_29go_left, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("go_right"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_31go_right, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("has_left"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_33has_left, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("has_right"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_35has_right, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("succ_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_37succ_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_36succ_item)}, - {__Pyx_NAMESTR("prev_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_39prev_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_38prev_item)}, - {__Pyx_NAMESTR("floor_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_41floor_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_40floor_item)}, - {__Pyx_NAMESTR("ceiling_item"), (PyCFunction)__pyx_pw_8bintrees_7cwalker_7cWalker_43ceiling_item, METH_O, __Pyx_DOCSTR(__pyx_doc_8bintrees_7cwalker_7cWalker_42ceiling_item)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_cWalker = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_long*/ - #else - 0, /*reserved*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if PY_VERSION_HEX >= 0x02050000 - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_cWalker = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_cWalker = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_cWalker = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -static PyTypeObject __pyx_type_8bintrees_7cwalker_cWalker = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("bintrees.cwalker.cWalker"), /*tp_name*/ - sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8bintrees_7cwalker_cWalker, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_cWalker, /*tp_as_number*/ - &__pyx_tp_as_sequence_cWalker, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_cWalker, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_cWalker, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8bintrees_7cwalker_cWalker, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_8bintrees_7cwalker_cWalker, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("cwalker"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, - {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__is_valid, __pyx_k__is_valid, sizeof(__pyx_k__is_valid), 0, 0, 1, 1}, - {&__pyx_n_s__item, __pyx_k__item, sizeof(__pyx_k__item), 0, 0, 1, 1}, - {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1}, - {&__pyx_n_s__pop, __pyx_k__pop, sizeof(__pyx_k__pop), 0, 0, 1, 1}, - {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1}, - {&__pyx_n_s__push, __pyx_k__push, sizeof(__pyx_k__push), 0, 0, 1, 1}, - {&__pyx_n_s__reset, __pyx_k__reset, sizeof(__pyx_k__reset), 0, 0, 1, 1}, - {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "bintrees\cwalker.pyx":65 - * cpdef pop(self): - * if stack_is_empty(self.stack) != 0: - * raise IndexError('pop(): stack is empty') # <<<<<<<<<<<<<< - * self.node = stack_pop(self.stack) - * - */ - __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initcwalker(void); /*proto*/ -PyMODINIT_FUNC initcwalker(void) -#else -PyMODINIT_FUNC PyInit_cwalker(void); /*proto*/ -PyMODINIT_FUNC PyInit_cwalker(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_cwalker(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("cwalker"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "bintrees.cwalker")) { - if (unlikely(PyDict_SetItemString(modules, "bintrees.cwalker", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if CYTHON_COMPILING_IN_PYPY - Py_INCREF(__pyx_b); - #endif - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_bintrees__cwalker) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - __pyx_vtabptr_8bintrees_7cwalker_cWalker = &__pyx_vtable_8bintrees_7cwalker_cWalker; - __pyx_vtable_8bintrees_7cwalker_cWalker.set_tree = (void (*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *))__pyx_f_8bintrees_7cwalker_7cWalker_set_tree; - __pyx_vtable_8bintrees_7cwalker_cWalker.reset = (PyObject *(*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch))__pyx_f_8bintrees_7cwalker_7cWalker_reset; - __pyx_vtable_8bintrees_7cwalker_cWalker.push = (PyObject *(*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch))__pyx_f_8bintrees_7cwalker_7cWalker_push; - __pyx_vtable_8bintrees_7cwalker_cWalker.pop = (PyObject *(*)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch))__pyx_f_8bintrees_7cwalker_7cWalker_pop; - if (PyType_Ready(&__pyx_type_8bintrees_7cwalker_cWalker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8bintrees_7cwalker_cWalker.tp_dict, __pyx_vtabptr_8bintrees_7cwalker_cWalker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "cWalker", (PyObject *)&__pyx_type_8bintrees_7cwalker_cWalker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8bintrees_7cwalker_cWalker = &__pyx_type_8bintrees_7cwalker_cWalker; - /*--- Type import code ---*/ - /*--- Variable import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "bintrees\cwalker.pyx":32 - * - * @property - * def key(self): # <<<<<<<<<<<<<< - * return <object> self.node.key - * - */ - __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__key); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__key, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker); - - /* "bintrees\cwalker.pyx":36 - * - * @property - * def value(self): # <<<<<<<<<<<<<< - * return <object> self.node.value - * - */ - __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__value, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker); - - /* "bintrees\cwalker.pyx":40 - * - * @property - * def item(self): # <<<<<<<<<<<<<< - * return (<object>self.node.key, <object>self.node.value) - * - */ - __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__item); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__item, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker); - - /* "bintrees\cwalker.pyx":44 - * - * @property - * def is_valid(self): # <<<<<<<<<<<<<< - * return self.node != NULL - * - */ - __pyx_t_1 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker, __pyx_n_s__is_valid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict, __pyx_n_s__is_valid, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyType_Modified(__pyx_ptype_8bintrees_7cwalker_cWalker); - - /* "bintrees\cwalker.pyx":1 - * #!/usr/bin/env python # <<<<<<<<<<<<<< - * #coding:utf-8 - * # Author: mozman - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - if (__pyx_m) { - __Pyx_AddTraceback("init bintrees.cwalker", __pyx_clineno, __pyx_lineno, __pyx_filename); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init bintrees.cwalker"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif /* CYTHON_REFNANNY */ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != __pyx_b) { - PyErr_Clear(); - result = PyObject_GetAttr(__pyx_b, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; -#if CPYTHON_COMPILING_IN_PYPY - if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) - goto invalid_keyword; - return 1; -#else - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) - #endif - if (unlikely(!PyUnicode_Check(key))) - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - return 0; -#endif -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - Py_XINCREF(type); - if (!value || value == Py_None) - value = NULL; - else - Py_INCREF(value); - if (!tb || tb == Py_None) - tb = NULL; - else { - Py_INCREF(tb); - if (!PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - } - #if PY_VERSION_HEX < 0x02050000 - if (PyClass_Check(type)) { - #else - if (PyType_Check(type)) { - #endif -#if CYTHON_COMPILING_IN_PYPY - if (!value) { - Py_INCREF(Py_None); - value = Py_None; - } -#endif - PyErr_NormalizeException(&type, &value, &tb); - } else { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else /* Python 3+ */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - PyObject* owned_instance = NULL; - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } - else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; - } - } else { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause && cause != Py_None) { - PyObject *fixed_cause; - if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } - else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } - else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } -bad: - Py_XDECREF(owned_instance); - return; -} -#endif - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)PyLong_AsUnsignedLong(x); - } else { - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, - CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - -static int __Pyx_check_binary_version(void) { - char ctversion[4], rtversion[4]; - PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); - PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); - if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { - char message[200]; - PyOS_snprintf(message, sizeof(message), - "compiletime version %s of module '%.100s' " - "does not match runtime version %s", - ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else - return PyErr_WarnEx(NULL, message, 1); - #endif - } - return 0; -} - -static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - PyObject *ob = PyCapsule_New(vtable, 0, 0); -#else - PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); -#endif - if (!ob) - goto bad; - if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) - goto bad; - Py_DECREF(ob); - return 0; -bad: - Py_XDECREF(ob); - return -1; -} - -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */
diff --git a/third_party/bintrees/bintrees/cwalker.pxd b/third_party/bintrees/bintrees/cwalker.pxd deleted file mode 100644 index 412f80364..0000000 --- a/third_party/bintrees/bintrees/cwalker.pxd +++ /dev/null
@@ -1,19 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Created: 08.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -from ctrees cimport node_t -from stack cimport node_stack_t - -cdef class cWalker: - cdef node_t *node - cdef node_t *root - cdef node_stack_t *stack - - cdef void set_tree(self, node_t *root) - cpdef reset(self) - cpdef push(self) - cpdef pop(self)
diff --git a/third_party/bintrees/bintrees/cwalker.pyx b/third_party/bintrees/bintrees/cwalker.pyx deleted file mode 100644 index eb94104b..0000000 --- a/third_party/bintrees/bintrees/cwalker.pyx +++ /dev/null
@@ -1,133 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: tree walker for cython trees -# Created: 07.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -DEF MAXSTACK=32 - -from stack cimport * -from ctrees cimport * - -cdef class cWalker: - def __cinit__(self): - self.root = NULL - self.node = NULL - self.stack = stack_init(MAXSTACK) - - def __dealloc__(self): - stack_delete(self.stack) - - cdef void set_tree(self, node_t *root): - self.root = root - self.reset() - - cpdef reset(self): - stack_reset(self.stack) - self.node = self.root - - @property - def key(self): - return <object> self.node.key - - @property - def value(self): - return <object> self.node.value - - @property - def item(self): - return (<object>self.node.key, <object>self.node.value) - - @property - def is_valid(self): - return self.node != NULL - - def goto(self, key): - cdef int cval - self.node = self.root - while self.node != NULL: - cval = ct_compare(key, <object> self.node.key) - if cval == 0: - return True - elif cval < 0: - self.node = self.node.link[0] - else: - self.node = self.node.link[1] - return False - - cpdef push(self): - stack_push(self.stack, self.node) - - cpdef pop(self): - if stack_is_empty(self.stack) != 0: - raise IndexError('pop(): stack is empty') - self.node = stack_pop(self.stack) - - def stack_is_empty(self): - return <bint> stack_is_empty(self.stack) - - def goto_leaf(self): - """ get a leaf node """ - while self.node != NULL: - if self.node.link[0] != NULL: - self.node = self.node.link[0] - elif self.node.link[1] != NULL: - self.node = self.node.link[1] - else: - return - - def has_child(self, int direction): - return self.node.link[direction] != NULL - - def down(self, int direction): - self.node = self.node.link[direction] - - def go_left(self): - self.node = self.node.link[0] - - def go_right(self): - self.node = self.node.link[1] - - def has_left(self): - return self.node.link[0] != NULL - - def has_right(self): - return self.node.link[1] != NULL - - def succ_item(self, key): - """ Get successor (k,v) pair of key, raises KeyError if key is max key - or key does not exist. - """ - self.node = ct_succ_node(self.root, key) - if self.node == NULL: # given key is biggest in tree - raise KeyError(str(key)) - return (<object> self.node.key, <object> self.node.value) - - def prev_item(self, key): - """ Get predecessor (k,v) pair of key, raises KeyError if key is min key - or key does not exist. - """ - self.node = ct_prev_node(self.root, key) - if self.node == NULL: # given key is smallest in tree - raise KeyError(str(key)) - return (<object> self.node.key, <object> self.node.value) - - def floor_item(self, key): - """ Get the element (k,v) pair associated with the greatest key less - than or equal to the given key, raises KeyError if there is no such key. - """ - self.node = ct_floor_node(self.root, key) - if self.node == NULL: # given key is smaller than min-key in tree - raise KeyError(str(key)) - return (<object> self.node.key, <object> self.node.value) - - def ceiling_item(self, key): - """ Get the element (k,v) pair associated with the smallest key greater - than or equal to the given key, raises KeyError if there is no such key. - """ - self.node = ct_ceiling_node(self.root, key) - if self.node == NULL: # given key is greater than max-key in tree - raise KeyError(str(key)) - return (<object> self.node.key, <object> self.node.value)
diff --git a/third_party/bintrees/bintrees/qavltree.c b/third_party/bintrees/bintrees/qavltree.c deleted file mode 100644 index 8c7c563..0000000 --- a/third_party/bintrees/bintrees/qavltree.c +++ /dev/null
@@ -1,3402 +0,0 @@ -/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. -#else -#include <stddef.h> /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef Py_HUGE_VAL - #define Py_HUGE_VAL HUGE_VAL -#endif -#ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 -#else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define CYTHON_FORMAT_SSIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ - (PyErr_Format(PyExc_TypeError, \ - "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ - (PyObject*)0)) - #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \ - !PyComplex_Check(o)) - #define PyIndex_Check __Pyx_PyIndex_Check - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" - #define CYTHON_FORMAT_SSIZE_T "z" - #define __Pyx_PyIndex_Check PyIndex_Check -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) - #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ - 0 : _PyUnicode_Ready((PyObject *)(op))) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) - #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) -#else - #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_READY(op) (0) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif -#ifndef PySet_CheckExact - #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) -#if PY_MAJOR_VERSION >= 3 - #define PyIntObject PyLongObject - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBoolObject PyLongObject -#endif -#if PY_VERSION_HEX < 0x03020000 - typedef long Py_hash_t; - #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong -#else - #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t -#endif -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#ifndef __PYX_EXTERN_C - #ifdef __cplusplus - #define __PYX_EXTERN_C extern "C" - #else - #define __PYX_EXTERN_C extern - #endif -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include <math.h> -#define __PYX_HAVE__bintrees__qavltree -#define __PYX_HAVE_API__bintrees__qavltree -#include "ctrees.h" -#include "stack.h" -#ifdef _OPENMP -#include <omp.h> -#endif /* _OPENMP */ - -#ifdef PYREX_WITHOUT_ASSERTIONS -#define CYTHON_WITHOUT_ASSERTIONS -#endif - - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#if CYTHON_COMPILING_IN_CPYTHON -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) -#else -#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) -#endif -#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) - -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ - #define likely(x) (x) - #define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -static const char *__pyx_f[] = { - "qavltree.pyx", - "cwalker.pxd", -}; - -/*--- Type declarations ---*/ -struct __pyx_obj_8bintrees_7cwalker_cWalker; -struct __pyx_obj_8bintrees_8qavltree_cAVLTree; - -/* "cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ -struct __pyx_obj_8bintrees_7cwalker_cWalker { - PyObject_HEAD - struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab; - node_t *node; - node_t *root; - node_stack_t *stack; -}; - - -/* "bintrees\qavltree.pyx":16 - * from ctrees cimport * - * - * cdef class cAVLTree: # <<<<<<<<<<<<<< - * cdef node_t *_root - * cdef int _count - */ -struct __pyx_obj_8bintrees_8qavltree_cAVLTree { - PyObject_HEAD - node_t *_root; - int _count; -}; - - - -/* "cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ - -struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker { - void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *); - PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); -}; -static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker; -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ - #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; -#ifdef WITH_THREAD - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - if (acquire_gil) { \ - PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - } -#else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) -#endif - #define __Pyx_RefNannyFinishContext() \ - __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) - #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) - #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) -#else - #define __Pyx_RefNannyDeclarations - #define __Pyx_RefNannySetupContext(name, acquire_gil) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XINCREF(r) Py_XINCREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) - #define __Pyx_XGOTREF(r) - #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) -#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ - const char* function_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (PyList_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { /* inlined PySequence_GetItem() */ - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (unlikely(l < 0)) return NULL; - i += l; - } - return m->sq_item(o, i); - } - } -#else - if (PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static int __Pyx_check_binary_version(void); - -#if !defined(__Pyx_PyIdentifier_FromString) -#if PY_MAJOR_VERSION < 3 - #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) -#else - #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) -#endif -#endif - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ - -static void* __Pyx_GetVtable(PyObject *dict); /*proto*/ - -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - - -/* Module declarations from 'bintrees.ctrees' */ - -/* Module declarations from 'bintrees.stack' */ - -/* Module declarations from 'bintrees.cwalker' */ -static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0; - -/* Module declarations from 'bintrees.qavltree' */ -static PyTypeObject *__pyx_ptype_8bintrees_8qavltree_cAVLTree = 0; -#define __Pyx_MODULE_NAME "bintrees.qavltree" -int __pyx_module_is_main_bintrees__qavltree = 0; - -/* Implementation of 'bintrees.qavltree' */ -static PyObject *__pyx_builtin_property; -static PyObject *__pyx_builtin_KeyError; -static PyObject *__pyx_builtin_MemoryError; -static PyObject *__pyx_builtin_ValueError; -static int __pyx_pf_8bintrees_8qavltree_8cAVLTree___cinit__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_items); /* proto */ -static void __pyx_pf_8bintrees_8qavltree_8cAVLTree_2__dealloc__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_4count(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_6__getstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_8__setstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_state); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_10clear(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_12get_value(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_14get_walker(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_16insert(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_18remove(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_20max_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_22min_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self); /* proto */ -static char __pyx_k_1[] = "Can not allocate memory for node structure."; -static char __pyx_k_3[] = "Tree is empty"; -static char __pyx_k__key[] = "key"; -static char __pyx_k__count[] = "count"; -static char __pyx_k__items[] = "items"; -static char __pyx_k__value[] = "value"; -static char __pyx_k__update[] = "update"; -static char __pyx_k____all__[] = "__all__"; -static char __pyx_k__cWalker[] = "cWalker"; -static char __pyx_k__cwalker[] = "cwalker"; -static char __pyx_k__KeyError[] = "KeyError"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__cAVLTree[] = "cAVLTree"; -static char __pyx_k__property[] = "property"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__MemoryError[] = "MemoryError"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_kp_s_3; -static PyObject *__pyx_n_s__KeyError; -static PyObject *__pyx_n_s__MemoryError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____all__; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__cAVLTree; -static PyObject *__pyx_n_s__cWalker; -static PyObject *__pyx_n_s__count; -static PyObject *__pyx_n_s__cwalker; -static PyObject *__pyx_n_s__items; -static PyObject *__pyx_n_s__key; -static PyObject *__pyx_n_s__property; -static PyObject *__pyx_n_s__update; -static PyObject *__pyx_n_s__value; -static PyObject *__pyx_int_0; -static PyObject *__pyx_k_tuple_2; -static PyObject *__pyx_k_tuple_4; -static PyObject *__pyx_k_tuple_5; - -/* Python wrapper */ -static int __pyx_pw_8bintrees_8qavltree_8cAVLTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8bintrees_8qavltree_8cAVLTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_items = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__items,0}; - PyObject* values[1] = {0}; - - /* "bintrees\qavltree.pyx":20 - * cdef int _count - * - * def __cinit__(self, items=None): # <<<<<<<<<<<<<< - * self._root = NULL - * self._count = 0 - */ - values[0] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__items); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_items = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree___cinit__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), __pyx_v_items); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8bintrees_8qavltree_8cAVLTree___cinit__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_items) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "bintrees\qavltree.pyx":21 - * - * def __cinit__(self, items=None): - * self._root = NULL # <<<<<<<<<<<<<< - * self._count = 0 - * if items: - */ - __pyx_v_self->_root = NULL; - - /* "bintrees\qavltree.pyx":22 - * def __cinit__(self, items=None): - * self._root = NULL - * self._count = 0 # <<<<<<<<<<<<<< - * if items: - * self.update(items) - */ - __pyx_v_self->_count = 0; - - /* "bintrees\qavltree.pyx":23 - * self._root = NULL - * self._count = 0 - * if items: # <<<<<<<<<<<<<< - * self.update(items) - * - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_items); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "bintrees\qavltree.pyx":24 - * self._count = 0 - * if items: - * self.update(items) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_items); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_items); - __Pyx_GIVEREF(__pyx_v_items); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8bintrees_8qavltree_8cAVLTree_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8bintrees_8qavltree_8cAVLTree_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8bintrees_8qavltree_8cAVLTree_2__dealloc__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "bintrees\qavltree.pyx":26 - * self.update(items) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * ct_delete_tree(self._root) - * - */ - -static void __pyx_pf_8bintrees_8qavltree_8cAVLTree_2__dealloc__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "bintrees\qavltree.pyx":27 - * - * def __dealloc__(self): - * ct_delete_tree(self._root) # <<<<<<<<<<<<<< - * - * @property - */ - ct_delete_tree(__pyx_v_self->_root); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("count (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_4count(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":30 - * - * @property - * def count(self): # <<<<<<<<<<<<<< - * return self._count - * - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_4count(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("count", 0); - - /* "bintrees\qavltree.pyx":31 - * @property - * def count(self): - * return self._count # <<<<<<<<<<<<<< - * - * def __getstate__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.count", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_6__getstate__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":33 - * return self._count - * - * def __getstate__(self): # <<<<<<<<<<<<<< - * return dict(self.items()) - * - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_6__getstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getstate__", 0); - - /* "bintrees\qavltree.pyx":34 - * - * def __getstate__(self): - * return dict(self.items()) # <<<<<<<<<<<<<< - * - * def __setstate__(self, state): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_8__setstate__(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), ((PyObject *)__pyx_v_state)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":36 - * return dict(self.items()) - * - * def __setstate__(self, state): # <<<<<<<<<<<<<< - * self.update(state) - * - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_8__setstate__(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setstate__", 0); - - /* "bintrees\qavltree.pyx":37 - * - * def __setstate__(self, state): - * self.update(state) # <<<<<<<<<<<<<< - * - * def clear(self): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_10clear(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":39 - * self.update(state) - * - * def clear(self): # <<<<<<<<<<<<<< - * ct_delete_tree(self._root) - * self._count = 0 - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_10clear(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear", 0); - - /* "bintrees\qavltree.pyx":40 - * - * def clear(self): - * ct_delete_tree(self._root) # <<<<<<<<<<<<<< - * self._count = 0 - * self._root = NULL - */ - ct_delete_tree(__pyx_v_self->_root); - - /* "bintrees\qavltree.pyx":41 - * def clear(self): - * ct_delete_tree(self._root) - * self._count = 0 # <<<<<<<<<<<<<< - * self._root = NULL - * - */ - __pyx_v_self->_count = 0; - - /* "bintrees\qavltree.pyx":42 - * ct_delete_tree(self._root) - * self._count = 0 - * self._root = NULL # <<<<<<<<<<<<<< - * - * def get_value(self, key): - */ - __pyx_v_self->_root = NULL; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_value (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_12get_value(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":44 - * self._root = NULL - * - * def get_value(self, key): # <<<<<<<<<<<<<< - * result = <object> ct_get_item(self._root, key) - * if result is None: - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_12get_value(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_value", 0); - - /* "bintrees\qavltree.pyx":45 - * - * def get_value(self, key): - * result = <object> ct_get_item(self._root, key) # <<<<<<<<<<<<<< - * if result is None: - * raise KeyError(key) - */ - __pyx_t_1 = ct_get_item(__pyx_v_self->_root, __pyx_v_key); - __Pyx_INCREF(((PyObject *)__pyx_t_1)); - __pyx_v_result = ((PyObject *)__pyx_t_1); - - /* "bintrees\qavltree.pyx":46 - * def get_value(self, key): - * result = <object> ct_get_item(self._root, key) - * if result is None: # <<<<<<<<<<<<<< - * raise KeyError(key) - * else: - */ - __pyx_t_2 = (__pyx_v_result == Py_None); - if (__pyx_t_2) { - - /* "bintrees\qavltree.pyx":47 - * result = <object> ct_get_item(self._root, key) - * if result is None: - * raise KeyError(key) # <<<<<<<<<<<<<< - * else: - * return result[1] - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qavltree.pyx":49 - * raise KeyError(key) - * else: - * return result[1] # <<<<<<<<<<<<<< - * - * def get_walker(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_result, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_walker (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_14get_walker(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":51 - * return result[1] - * - * def get_walker(self): # <<<<<<<<<<<<<< - * cdef cWalker walker - * walker = cWalker() - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_14get_walker(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_walker = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_walker", 0); - - /* "bintrees\qavltree.pyx":53 - * def get_walker(self): - * cdef cWalker walker - * walker = cWalker() # <<<<<<<<<<<<<< - * walker.set_tree(self._root) - * return walker - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8bintrees_7cwalker_cWalker)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_walker = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "bintrees\qavltree.pyx":54 - * cdef cWalker walker - * walker = cWalker() - * walker.set_tree(self._root) # <<<<<<<<<<<<<< - * return walker - * - */ - ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_walker->__pyx_vtab)->set_tree(__pyx_v_walker, __pyx_v_self->_root); - - /* "bintrees\qavltree.pyx":55 - * walker = cWalker() - * walker.set_tree(self._root) - * return walker # <<<<<<<<<<<<<< - * - * def insert(self, key, value): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_walker)); - __pyx_r = ((PyObject *)__pyx_v_walker); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.get_walker", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_walker); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_key = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("insert (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__value,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_key = values[0]; - __pyx_v_value = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_16insert(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), __pyx_v_key, __pyx_v_value); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":57 - * return walker - * - * def insert(self, key, value): # <<<<<<<<<<<<<< - * res = avl_insert(&self._root, key, value) - * if res < 0: - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_16insert(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - PyObject *__pyx_v_res = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("insert", 0); - - /* "bintrees\qavltree.pyx":58 - * - * def insert(self, key, value): - * res = avl_insert(&self._root, key, value) # <<<<<<<<<<<<<< - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') - */ - __pyx_t_1 = PyInt_FromLong(avl_insert((&__pyx_v_self->_root), __pyx_v_key, __pyx_v_value)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_res = __pyx_t_1; - __pyx_t_1 = 0; - - /* "bintrees\qavltree.pyx":59 - * def insert(self, key, value): - * res = avl_insert(&self._root, key, value) - * if res < 0: # <<<<<<<<<<<<<< - * raise MemoryError('Can not allocate memory for node structure.') - * else: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_res, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "bintrees\qavltree.pyx":60 - * res = avl_insert(&self._root, key, value) - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<< - * else: - * self._count += res - */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qavltree.pyx":62 - * raise MemoryError('Can not allocate memory for node structure.') - * else: - * self._count += res # <<<<<<<<<<<<<< - * - * def remove(self, key): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_res); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_self->_count = __pyx_t_4; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_res); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("remove (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_18remove(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":64 - * self._count += res - * - * def remove(self, key): # <<<<<<<<<<<<<< - * cdef int result - * result = avl_remove(&self._root, key) - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_18remove(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_v_result; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("remove", 0); - - /* "bintrees\qavltree.pyx":66 - * def remove(self, key): - * cdef int result - * result = avl_remove(&self._root, key) # <<<<<<<<<<<<<< - * if result == 0: - * raise KeyError(str(key)) - */ - __pyx_v_result = avl_remove((&__pyx_v_self->_root), __pyx_v_key); - - /* "bintrees\qavltree.pyx":67 - * cdef int result - * result = avl_remove(&self._root, key) - * if result == 0: # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * else: - */ - __pyx_t_1 = (__pyx_v_result == 0); - if (__pyx_t_1) { - - /* "bintrees\qavltree.pyx":68 - * result = avl_remove(&self._root, key) - * if result == 0: - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * else: - * self._count -= 1 - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qavltree.pyx":70 - * raise KeyError(str(key)) - * else: - * self._count -= 1 # <<<<<<<<<<<<<< - * - * def max_item(self): - */ - __pyx_v_self->_count = (__pyx_v_self->_count - 1); - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.remove", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_8qavltree_8cAVLTree_20max_item[] = " Get item with max key of tree, raises ValueError if tree is empty. "; -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("max_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_20max_item(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":72 - * self._count -= 1 - * - * def max_item(self): # <<<<<<<<<<<<<< - * """ Get item with max key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_20max_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - node_t *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("max_item", 0); - - /* "bintrees\qavltree.pyx":75 - * """ Get item with max key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - * node = ct_max_node(self._root) # <<<<<<<<<<<<<< - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - */ - __pyx_v_node = ct_max_node(__pyx_v_self->_root); - - /* "bintrees\qavltree.pyx":76 - * cdef node_t *node - * node = ct_max_node(self._root) - * if node == NULL: # root is None # <<<<<<<<<<<<<< - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) - */ - __pyx_t_1 = (__pyx_v_node == NULL); - if (__pyx_t_1) { - - /* "bintrees\qavltree.pyx":77 - * node = ct_max_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qavltree.pyx":78 - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<< - * - * def min_item(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_node->key)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_node->value)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value)); - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.max_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_8qavltree_8cAVLTree_22min_item[] = " Get item with min key of tree, raises ValueError if tree is empty. "; -static PyObject *__pyx_pw_8bintrees_8qavltree_8cAVLTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("min_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qavltree_8cAVLTree_22min_item(((struct __pyx_obj_8bintrees_8qavltree_cAVLTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qavltree.pyx":80 - * return (<object>node.key, <object>node.value) - * - * def min_item(self): # <<<<<<<<<<<<<< - * """ Get item with min key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - */ - -static PyObject *__pyx_pf_8bintrees_8qavltree_8cAVLTree_22min_item(struct __pyx_obj_8bintrees_8qavltree_cAVLTree *__pyx_v_self) { - node_t *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("min_item", 0); - - /* "bintrees\qavltree.pyx":83 - * """ Get item with min key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - * node = ct_min_node(self._root) # <<<<<<<<<<<<<< - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - */ - __pyx_v_node = ct_min_node(__pyx_v_self->_root); - - /* "bintrees\qavltree.pyx":84 - * cdef node_t *node - * node = ct_min_node(self._root) - * if node == NULL: # root is None # <<<<<<<<<<<<<< - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) - */ - __pyx_t_1 = (__pyx_v_node == NULL); - if (__pyx_t_1) { - - /* "bintrees\qavltree.pyx":85 - * node = ct_min_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qavltree.pyx":86 - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<< - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_node->key)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_node->value)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value)); - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qavltree.cAVLTree.min_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_tp_new_8bintrees_8qavltree_cAVLTree(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - if (__pyx_pw_8bintrees_8qavltree_8cAVLTree_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8bintrees_8qavltree_cAVLTree(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8bintrees_8qavltree_8cAVLTree_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_8bintrees_8qavltree_cAVLTree[] = { - {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_5count, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_7__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_9__setstate__, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_11clear, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_value"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_13get_value, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_walker"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_15get_walker, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_17insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("remove"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_19remove, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("max_item"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_21max_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qavltree_8cAVLTree_20max_item)}, - {__Pyx_NAMESTR("min_item"), (PyCFunction)__pyx_pw_8bintrees_8qavltree_8cAVLTree_23min_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qavltree_8cAVLTree_22min_item)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_cAVLTree = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_long*/ - #else - 0, /*reserved*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if PY_VERSION_HEX >= 0x02050000 - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_cAVLTree = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_cAVLTree = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_cAVLTree = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -static PyTypeObject __pyx_type_8bintrees_8qavltree_cAVLTree = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("bintrees.qavltree.cAVLTree"), /*tp_name*/ - sizeof(struct __pyx_obj_8bintrees_8qavltree_cAVLTree), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8bintrees_8qavltree_cAVLTree, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_cAVLTree, /*tp_as_number*/ - &__pyx_tp_as_sequence_cAVLTree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_cAVLTree, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_cAVLTree, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8bintrees_8qavltree_cAVLTree, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_8bintrees_8qavltree_cAVLTree, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("qavltree"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, - {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, - {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__cAVLTree, __pyx_k__cAVLTree, sizeof(__pyx_k__cAVLTree), 0, 0, 1, 1}, - {&__pyx_n_s__cWalker, __pyx_k__cWalker, sizeof(__pyx_k__cWalker), 0, 0, 1, 1}, - {&__pyx_n_s__count, __pyx_k__count, sizeof(__pyx_k__count), 0, 0, 1, 1}, - {&__pyx_n_s__cwalker, __pyx_k__cwalker, sizeof(__pyx_k__cwalker), 0, 0, 1, 1}, - {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1}, - {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1}, - {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1}, - {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1}, - {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "bintrees\qavltree.pyx":60 - * res = avl_insert(&self._root, key, value) - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<< - * else: - * self._count += res - */ - __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); - - /* "bintrees\qavltree.pyx":77 - * node = ct_max_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); - - /* "bintrees\qavltree.pyx":85 - * node = ct_min_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initqavltree(void); /*proto*/ -PyMODINIT_FUNC initqavltree(void) -#else -PyMODINIT_FUNC PyInit_qavltree(void); /*proto*/ -PyMODINIT_FUNC PyInit_qavltree(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_qavltree(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("qavltree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "bintrees.qavltree")) { - if (unlikely(PyDict_SetItemString(modules, "bintrees.qavltree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if CYTHON_COMPILING_IN_PYPY - Py_INCREF(__pyx_b); - #endif - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_bintrees__qavltree) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_8bintrees_8qavltree_cAVLTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "cAVLTree", (PyObject *)&__pyx_type_8bintrees_8qavltree_cAVLTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8bintrees_8qavltree_cAVLTree = &__pyx_type_8bintrees_8qavltree_cAVLTree; - /*--- Type import code ---*/ - __pyx_ptype_8bintrees_7cwalker_cWalker = __Pyx_ImportType("bintrees.cwalker", "cWalker", sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), 1); if (unlikely(!__pyx_ptype_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_vtabptr_8bintrees_7cwalker_cWalker = (struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker*)__Pyx_GetVtable(__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict); if (unlikely(!__pyx_vtabptr_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Variable import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "bintrees\qavltree.pyx":9 - * # License: MIT License - * - * __all__ = ['cAVLTree'] # <<<<<<<<<<<<<< - * - * from cwalker import cWalker - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__cAVLTree)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cAVLTree)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cAVLTree)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "bintrees\qavltree.pyx":11 - * __all__ = ['cAVLTree'] - * - * from cwalker import cWalker # <<<<<<<<<<<<<< - * - * from cwalker cimport * - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__cWalker)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cWalker)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cWalker)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__cwalker), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "bintrees\qavltree.pyx":30 - * - * @property - * def count(self): # <<<<<<<<<<<<<< - * return self._count - * - */ - __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_8qavltree_cAVLTree, __pyx_n_s__count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_8qavltree_cAVLTree->tp_dict, __pyx_n_s__count, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_ptype_8bintrees_8qavltree_cAVLTree); - - /* "bintrees\qavltree.pyx":1 - * #!/usr/bin/env python # <<<<<<<<<<<<<< - * #coding:utf-8 - * # Author: mozman - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - if (__pyx_m) { - __Pyx_AddTraceback("init bintrees.qavltree", __pyx_clineno, __pyx_lineno, __pyx_filename); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init bintrees.qavltree"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif /* CYTHON_REFNANNY */ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != __pyx_b) { - PyErr_Clear(); - result = PyObject_GetAttr(__pyx_b, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AsString(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - continue; - } - name = first_kw_arg; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { - while (*name) { - if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) - && _PyString_Eq(**name, key)) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - if ((**argname == key) || ( - (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) - && _PyString_Eq(**argname, key))) { - goto arg_passed_twice; - } - argname++; - } - } - } else - #endif - if (likely(PyUnicode_Check(key))) { - while (*name) { - int cmp = (**name == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**name, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - int cmp = (**argname == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**argname, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) goto arg_passed_twice; - argname++; - } - } - } else - goto invalid_keyword_type; - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, key); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - Py_XINCREF(type); - if (!value || value == Py_None) - value = NULL; - else - Py_INCREF(value); - if (!tb || tb == Py_None) - tb = NULL; - else { - Py_INCREF(tb); - if (!PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - } - #if PY_VERSION_HEX < 0x02050000 - if (PyClass_Check(type)) { - #else - if (PyType_Check(type)) { - #endif -#if CYTHON_COMPILING_IN_PYPY - if (!value) { - Py_INCREF(Py_None); - value = Py_None; - } -#endif - PyErr_NormalizeException(&type, &value, &tb); - } else { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else /* Python 3+ */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - PyObject* owned_instance = NULL; - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } - else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; - } - } else { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause && cause != Py_None) { - PyObject *fixed_cause; - if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } - else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } - else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } -bad: - Py_XDECREF(owned_instance); - return; -} -#endif - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { - PyObject *py_import = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!py_import) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - #if PY_VERSION_HEX >= 0x02050000 - { - #if PY_MAJOR_VERSION >= 3 - if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { - /* try package relative import first */ - PyObject *py_level = PyInt_FromLong(1); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - if (!module) { - if (!PyErr_ExceptionMatches(PyExc_ImportError)) - goto bad; - PyErr_Clear(); - } - } - level = 0; /* try absolute import on failure */ - } - #endif - if (!module) { - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - } - } - #else - if (level>0) { - PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); - goto bad; - } - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); - #endif -bad: - Py_XDECREF(empty_list); - Py_XDECREF(py_import); - Py_XDECREF(empty_dict); - return module; -} - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)PyLong_AsUnsignedLong(x); - } else { - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static int __Pyx_check_binary_version(void) { - char ctversion[4], rtversion[4]; - PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); - PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); - if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { - char message[200]; - PyOS_snprintf(message, sizeof(message), - "compiletime version %s of module '%.100s' " - "does not match runtime version %s", - ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else - return PyErr_WarnEx(NULL, message, 1); - #endif - } - return 0; -} - -#ifndef __PYX_HAVE_RT_ImportModule -#define __PYX_HAVE_RT_ImportModule -static PyObject *__Pyx_ImportModule(const char *name) { - PyObject *py_name = 0; - PyObject *py_module = 0; - py_name = __Pyx_PyIdentifier_FromString(name); - if (!py_name) - goto bad; - py_module = PyImport_Import(py_name); - Py_DECREF(py_name); - return py_module; -bad: - Py_XDECREF(py_name); - return 0; -} -#endif - -#ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, - size_t size, int strict) -{ - PyObject *py_module = 0; - PyObject *result = 0; - PyObject *py_name = 0; - char warning[200]; - py_module = __Pyx_ImportModule(module_name); - if (!py_module) - goto bad; - py_name = __Pyx_PyIdentifier_FromString(class_name); - if (!py_name) - goto bad; - result = PyObject_GetAttr(py_module, py_name); - Py_DECREF(py_name); - py_name = 0; - Py_DECREF(py_module); - py_module = 0; - if (!result) - goto bad; - if (!PyType_Check(result)) { - PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", - module_name, class_name); - goto bad; - } - if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility", - module_name, class_name); - #if PY_VERSION_HEX < 0x02050000 - if (PyErr_Warn(NULL, warning) < 0) goto bad; - #else - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - #endif - } - else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", - module_name, class_name); - goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(py_module); - Py_XDECREF(result); - return NULL; -} -#endif - -static void* __Pyx_GetVtable(PyObject *dict) { - void* ptr; - PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); - if (!ob) - goto bad; -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - ptr = PyCapsule_GetPointer(ob, 0); -#else - ptr = PyCObject_AsVoidPtr(ob); -#endif - if (!ptr && !PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); - Py_DECREF(ob); - return ptr; -bad: - Py_XDECREF(ob); - return NULL; -} - -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */
diff --git a/third_party/bintrees/bintrees/qavltree.pyx b/third_party/bintrees/bintrees/qavltree.pyx deleted file mode 100644 index b6844b8..0000000 --- a/third_party/bintrees/bintrees/qavltree.pyx +++ /dev/null
@@ -1,87 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: cython unbalanced binary tree module -# Created: 28.04.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -__all__ = ['cAVLTree'] - -from cwalker import cWalker - -from cwalker cimport * -from ctrees cimport * - -cdef class cAVLTree: - cdef node_t *_root - cdef int _count - - def __cinit__(self, items=None): - self._root = NULL - self._count = 0 - if items: - self.update(items) - - def __dealloc__(self): - ct_delete_tree(self._root) - - @property - def count(self): - return self._count - - def __getstate__(self): - return dict(self.items()) - - def __setstate__(self, state): - self.update(state) - - def clear(self): - ct_delete_tree(self._root) - self._count = 0 - self._root = NULL - - def get_value(self, key): - result = <object> ct_get_item(self._root, key) - if result is None: - raise KeyError(key) - else: - return result[1] - - def get_walker(self): - cdef cWalker walker - walker = cWalker() - walker.set_tree(self._root) - return walker - - def insert(self, key, value): - res = avl_insert(&self._root, key, value) - if res < 0: - raise MemoryError('Can not allocate memory for node structure.') - else: - self._count += res - - def remove(self, key): - cdef int result - result = avl_remove(&self._root, key) - if result == 0: - raise KeyError(str(key)) - else: - self._count -= 1 - - def max_item(self): - """ Get item with max key of tree, raises ValueError if tree is empty. """ - cdef node_t *node - node = ct_max_node(self._root) - if node == NULL: # root is None - raise ValueError("Tree is empty") - return (<object>node.key, <object>node.value) - - def min_item(self): - """ Get item with min key of tree, raises ValueError if tree is empty. """ - cdef node_t *node - node = ct_min_node(self._root) - if node == NULL: # root is None - raise ValueError("Tree is empty") - return (<object>node.key, <object>node.value) -
diff --git a/third_party/bintrees/bintrees/qbintree.c b/third_party/bintrees/bintrees/qbintree.c deleted file mode 100644 index e3c390d..0000000 --- a/third_party/bintrees/bintrees/qbintree.c +++ /dev/null
@@ -1,3397 +0,0 @@ -/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. -#else -#include <stddef.h> /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef Py_HUGE_VAL - #define Py_HUGE_VAL HUGE_VAL -#endif -#ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 -#else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define CYTHON_FORMAT_SSIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ - (PyErr_Format(PyExc_TypeError, \ - "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ - (PyObject*)0)) - #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \ - !PyComplex_Check(o)) - #define PyIndex_Check __Pyx_PyIndex_Check - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" - #define CYTHON_FORMAT_SSIZE_T "z" - #define __Pyx_PyIndex_Check PyIndex_Check -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) - #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ - 0 : _PyUnicode_Ready((PyObject *)(op))) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) - #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) -#else - #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_READY(op) (0) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif -#ifndef PySet_CheckExact - #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) -#if PY_MAJOR_VERSION >= 3 - #define PyIntObject PyLongObject - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBoolObject PyLongObject -#endif -#if PY_VERSION_HEX < 0x03020000 - typedef long Py_hash_t; - #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong -#else - #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t -#endif -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#ifndef __PYX_EXTERN_C - #ifdef __cplusplus - #define __PYX_EXTERN_C extern "C" - #else - #define __PYX_EXTERN_C extern - #endif -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include <math.h> -#define __PYX_HAVE__bintrees__qbintree -#define __PYX_HAVE_API__bintrees__qbintree -#include "ctrees.h" -#include "stack.h" -#ifdef _OPENMP -#include <omp.h> -#endif /* _OPENMP */ - -#ifdef PYREX_WITHOUT_ASSERTIONS -#define CYTHON_WITHOUT_ASSERTIONS -#endif - - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#if CYTHON_COMPILING_IN_CPYTHON -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) -#else -#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) -#endif -#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) - -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ - #define likely(x) (x) - #define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -static const char *__pyx_f[] = { - "qbintree.pyx", - "cwalker.pxd", -}; - -/*--- Type declarations ---*/ -struct __pyx_obj_8bintrees_7cwalker_cWalker; -struct __pyx_obj_8bintrees_8qbintree_cBinaryTree; - -/* "cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ -struct __pyx_obj_8bintrees_7cwalker_cWalker { - PyObject_HEAD - struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab; - node_t *node; - node_t *root; - node_stack_t *stack; -}; - - -/* "bintrees\qbintree.pyx":16 - * from ctrees cimport * - * - * cdef class cBinaryTree: # <<<<<<<<<<<<<< - * cdef node_t *_root - * cdef int _count - */ -struct __pyx_obj_8bintrees_8qbintree_cBinaryTree { - PyObject_HEAD - node_t *_root; - int _count; -}; - - - -/* "cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ - -struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker { - void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *); - PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); -}; -static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker; -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ - #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; -#ifdef WITH_THREAD - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - if (acquire_gil) { \ - PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - } -#else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) -#endif - #define __Pyx_RefNannyFinishContext() \ - __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) - #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) - #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) -#else - #define __Pyx_RefNannyDeclarations - #define __Pyx_RefNannySetupContext(name, acquire_gil) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XINCREF(r) Py_XINCREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) - #define __Pyx_XGOTREF(r) - #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) -#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ - const char* function_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (PyList_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { /* inlined PySequence_GetItem() */ - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (unlikely(l < 0)) return NULL; - i += l; - } - return m->sq_item(o, i); - } - } -#else - if (PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static int __Pyx_check_binary_version(void); - -#if !defined(__Pyx_PyIdentifier_FromString) -#if PY_MAJOR_VERSION < 3 - #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) -#else - #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) -#endif -#endif - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ - -static void* __Pyx_GetVtable(PyObject *dict); /*proto*/ - -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - - -/* Module declarations from 'bintrees.ctrees' */ - -/* Module declarations from 'bintrees.stack' */ - -/* Module declarations from 'bintrees.cwalker' */ -static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0; - -/* Module declarations from 'bintrees.qbintree' */ -static PyTypeObject *__pyx_ptype_8bintrees_8qbintree_cBinaryTree = 0; -#define __Pyx_MODULE_NAME "bintrees.qbintree" -int __pyx_module_is_main_bintrees__qbintree = 0; - -/* Implementation of 'bintrees.qbintree' */ -static PyObject *__pyx_builtin_property; -static PyObject *__pyx_builtin_KeyError; -static PyObject *__pyx_builtin_MemoryError; -static PyObject *__pyx_builtin_ValueError; -static int __pyx_pf_8bintrees_8qbintree_11cBinaryTree___cinit__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_items); /* proto */ -static void __pyx_pf_8bintrees_8qbintree_11cBinaryTree_2__dealloc__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_4count(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_6__getstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_8__setstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_state); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_10clear(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_12get_value(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_14get_walker(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_16insert(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_18remove(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_20max_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_22min_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self); /* proto */ -static char __pyx_k_1[] = "Can not allocate memory for node structure."; -static char __pyx_k_3[] = "Tree is empty"; -static char __pyx_k__key[] = "key"; -static char __pyx_k__count[] = "count"; -static char __pyx_k__items[] = "items"; -static char __pyx_k__value[] = "value"; -static char __pyx_k__update[] = "update"; -static char __pyx_k____all__[] = "__all__"; -static char __pyx_k__cWalker[] = "cWalker"; -static char __pyx_k__cwalker[] = "cwalker"; -static char __pyx_k__KeyError[] = "KeyError"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__property[] = "property"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__MemoryError[] = "MemoryError"; -static char __pyx_k__cBinaryTree[] = "cBinaryTree"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_kp_s_3; -static PyObject *__pyx_n_s__KeyError; -static PyObject *__pyx_n_s__MemoryError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____all__; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__cBinaryTree; -static PyObject *__pyx_n_s__cWalker; -static PyObject *__pyx_n_s__count; -static PyObject *__pyx_n_s__cwalker; -static PyObject *__pyx_n_s__items; -static PyObject *__pyx_n_s__key; -static PyObject *__pyx_n_s__property; -static PyObject *__pyx_n_s__update; -static PyObject *__pyx_n_s__value; -static PyObject *__pyx_int_0; -static PyObject *__pyx_k_tuple_2; -static PyObject *__pyx_k_tuple_4; -static PyObject *__pyx_k_tuple_5; - -/* Python wrapper */ -static int __pyx_pw_8bintrees_8qbintree_11cBinaryTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8bintrees_8qbintree_11cBinaryTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_items = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__items,0}; - PyObject* values[1] = {0}; - - /* "bintrees\qbintree.pyx":20 - * cdef int _count - * - * def __cinit__(self, items=None): # <<<<<<<<<<<<<< - * self._root = NULL - * self._count = 0 - */ - values[0] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__items); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_items = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree___cinit__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), __pyx_v_items); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8bintrees_8qbintree_11cBinaryTree___cinit__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_items) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "bintrees\qbintree.pyx":21 - * - * def __cinit__(self, items=None): - * self._root = NULL # <<<<<<<<<<<<<< - * self._count = 0 - * if items: - */ - __pyx_v_self->_root = NULL; - - /* "bintrees\qbintree.pyx":22 - * def __cinit__(self, items=None): - * self._root = NULL - * self._count = 0 # <<<<<<<<<<<<<< - * if items: - * self.update(items) - */ - __pyx_v_self->_count = 0; - - /* "bintrees\qbintree.pyx":23 - * self._root = NULL - * self._count = 0 - * if items: # <<<<<<<<<<<<<< - * self.update(items) - * - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_items); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "bintrees\qbintree.pyx":24 - * self._count = 0 - * if items: - * self.update(items) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_items); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_items); - __Pyx_GIVEREF(__pyx_v_items); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8bintrees_8qbintree_11cBinaryTree_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8bintrees_8qbintree_11cBinaryTree_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8bintrees_8qbintree_11cBinaryTree_2__dealloc__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "bintrees\qbintree.pyx":26 - * self.update(items) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * ct_delete_tree(self._root) - * - */ - -static void __pyx_pf_8bintrees_8qbintree_11cBinaryTree_2__dealloc__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "bintrees\qbintree.pyx":27 - * - * def __dealloc__(self): - * ct_delete_tree(self._root) # <<<<<<<<<<<<<< - * - * @property - */ - ct_delete_tree(__pyx_v_self->_root); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("count (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_4count(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":30 - * - * @property - * def count(self): # <<<<<<<<<<<<<< - * return self._count - * - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_4count(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("count", 0); - - /* "bintrees\qbintree.pyx":31 - * @property - * def count(self): - * return self._count # <<<<<<<<<<<<<< - * - * def __getstate__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.count", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_6__getstate__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":33 - * return self._count - * - * def __getstate__(self): # <<<<<<<<<<<<<< - * return dict(self.items()) - * - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_6__getstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getstate__", 0); - - /* "bintrees\qbintree.pyx":34 - * - * def __getstate__(self): - * return dict(self.items()) # <<<<<<<<<<<<<< - * - * def __setstate__(self, state): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_8__setstate__(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), ((PyObject *)__pyx_v_state)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":36 - * return dict(self.items()) - * - * def __setstate__(self, state): # <<<<<<<<<<<<<< - * self.update(state) - * - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_8__setstate__(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setstate__", 0); - - /* "bintrees\qbintree.pyx":37 - * - * def __setstate__(self, state): - * self.update(state) # <<<<<<<<<<<<<< - * - * def clear(self): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_10clear(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":39 - * self.update(state) - * - * def clear(self): # <<<<<<<<<<<<<< - * ct_delete_tree(self._root) - * self._count = 0 - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_10clear(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear", 0); - - /* "bintrees\qbintree.pyx":40 - * - * def clear(self): - * ct_delete_tree(self._root) # <<<<<<<<<<<<<< - * self._count = 0 - * self._root = NULL - */ - ct_delete_tree(__pyx_v_self->_root); - - /* "bintrees\qbintree.pyx":41 - * def clear(self): - * ct_delete_tree(self._root) - * self._count = 0 # <<<<<<<<<<<<<< - * self._root = NULL - * - */ - __pyx_v_self->_count = 0; - - /* "bintrees\qbintree.pyx":42 - * ct_delete_tree(self._root) - * self._count = 0 - * self._root = NULL # <<<<<<<<<<<<<< - * - * def get_value(self, key): - */ - __pyx_v_self->_root = NULL; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_value (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_12get_value(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":44 - * self._root = NULL - * - * def get_value(self, key): # <<<<<<<<<<<<<< - * result = <object> ct_get_item(self._root, key) - * if result is None: - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_12get_value(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_value", 0); - - /* "bintrees\qbintree.pyx":45 - * - * def get_value(self, key): - * result = <object> ct_get_item(self._root, key) # <<<<<<<<<<<<<< - * if result is None: - * raise KeyError(key) - */ - __pyx_t_1 = ct_get_item(__pyx_v_self->_root, __pyx_v_key); - __Pyx_INCREF(((PyObject *)__pyx_t_1)); - __pyx_v_result = ((PyObject *)__pyx_t_1); - - /* "bintrees\qbintree.pyx":46 - * def get_value(self, key): - * result = <object> ct_get_item(self._root, key) - * if result is None: # <<<<<<<<<<<<<< - * raise KeyError(key) - * else: - */ - __pyx_t_2 = (__pyx_v_result == Py_None); - if (__pyx_t_2) { - - /* "bintrees\qbintree.pyx":47 - * result = <object> ct_get_item(self._root, key) - * if result is None: - * raise KeyError(key) # <<<<<<<<<<<<<< - * else: - * return result[1] - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qbintree.pyx":49 - * raise KeyError(key) - * else: - * return result[1] # <<<<<<<<<<<<<< - * - * def get_walker(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_result, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_walker (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_14get_walker(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":51 - * return result[1] - * - * def get_walker(self): # <<<<<<<<<<<<<< - * cdef cWalker walker - * walker = cWalker() - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_14get_walker(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_walker = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_walker", 0); - - /* "bintrees\qbintree.pyx":53 - * def get_walker(self): - * cdef cWalker walker - * walker = cWalker() # <<<<<<<<<<<<<< - * walker.set_tree(self._root) - * return walker - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8bintrees_7cwalker_cWalker)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_walker = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "bintrees\qbintree.pyx":54 - * cdef cWalker walker - * walker = cWalker() - * walker.set_tree(self._root) # <<<<<<<<<<<<<< - * return walker - * - */ - ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_walker->__pyx_vtab)->set_tree(__pyx_v_walker, __pyx_v_self->_root); - - /* "bintrees\qbintree.pyx":55 - * walker = cWalker() - * walker.set_tree(self._root) - * return walker # <<<<<<<<<<<<<< - * - * def insert(self, key, value): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_walker)); - __pyx_r = ((PyObject *)__pyx_v_walker); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.get_walker", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_walker); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_key = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("insert (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__value,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_key = values[0]; - __pyx_v_value = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_16insert(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), __pyx_v_key, __pyx_v_value); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":57 - * return walker - * - * def insert(self, key, value): # <<<<<<<<<<<<<< - * res = ct_bintree_insert(&self._root, key, value) - * if res < 0: - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_16insert(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - PyObject *__pyx_v_res = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("insert", 0); - - /* "bintrees\qbintree.pyx":58 - * - * def insert(self, key, value): - * res = ct_bintree_insert(&self._root, key, value) # <<<<<<<<<<<<<< - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') - */ - __pyx_t_1 = PyInt_FromLong(ct_bintree_insert((&__pyx_v_self->_root), __pyx_v_key, __pyx_v_value)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_res = __pyx_t_1; - __pyx_t_1 = 0; - - /* "bintrees\qbintree.pyx":59 - * def insert(self, key, value): - * res = ct_bintree_insert(&self._root, key, value) - * if res < 0: # <<<<<<<<<<<<<< - * raise MemoryError('Can not allocate memory for node structure.') - * self._count += res - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_res, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "bintrees\qbintree.pyx":60 - * res = ct_bintree_insert(&self._root, key, value) - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<< - * self._count += res - * - */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qbintree.pyx":61 - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') - * self._count += res # <<<<<<<<<<<<<< - * - * def remove(self, key): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_res); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_self->_count = __pyx_t_4; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_res); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("remove (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_18remove(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":63 - * self._count += res - * - * def remove(self, key): # <<<<<<<<<<<<<< - * cdef int result - * result = ct_bintree_remove(&self._root, key) - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_18remove(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_v_result; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("remove", 0); - - /* "bintrees\qbintree.pyx":65 - * def remove(self, key): - * cdef int result - * result = ct_bintree_remove(&self._root, key) # <<<<<<<<<<<<<< - * if result == 0: - * raise KeyError(str(key)) - */ - __pyx_v_result = ct_bintree_remove((&__pyx_v_self->_root), __pyx_v_key); - - /* "bintrees\qbintree.pyx":66 - * cdef int result - * result = ct_bintree_remove(&self._root, key) - * if result == 0: # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * else: - */ - __pyx_t_1 = (__pyx_v_result == 0); - if (__pyx_t_1) { - - /* "bintrees\qbintree.pyx":67 - * result = ct_bintree_remove(&self._root, key) - * if result == 0: - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * else: - * self._count -= 1 - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qbintree.pyx":69 - * raise KeyError(str(key)) - * else: - * self._count -= 1 # <<<<<<<<<<<<<< - * - * def max_item(self): - */ - __pyx_v_self->_count = (__pyx_v_self->_count - 1); - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.remove", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_8qbintree_11cBinaryTree_20max_item[] = " Get item with max key of tree, raises ValueError if tree is empty. "; -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("max_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_20max_item(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":71 - * self._count -= 1 - * - * def max_item(self): # <<<<<<<<<<<<<< - * """ Get item with max key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_20max_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - node_t *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("max_item", 0); - - /* "bintrees\qbintree.pyx":74 - * """ Get item with max key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - * node = ct_max_node(self._root) # <<<<<<<<<<<<<< - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - */ - __pyx_v_node = ct_max_node(__pyx_v_self->_root); - - /* "bintrees\qbintree.pyx":75 - * cdef node_t *node - * node = ct_max_node(self._root) - * if node == NULL: # root is None # <<<<<<<<<<<<<< - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) - */ - __pyx_t_1 = (__pyx_v_node == NULL); - if (__pyx_t_1) { - - /* "bintrees\qbintree.pyx":76 - * node = ct_max_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qbintree.pyx":77 - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<< - * - * def min_item(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_node->key)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_node->value)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value)); - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.max_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_8qbintree_11cBinaryTree_22min_item[] = " Get item with min key of tree, raises ValueError if tree is empty. "; -static PyObject *__pyx_pw_8bintrees_8qbintree_11cBinaryTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("min_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_8qbintree_11cBinaryTree_22min_item(((struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qbintree.pyx":79 - * return (<object>node.key, <object>node.value) - * - * def min_item(self): # <<<<<<<<<<<<<< - * """ Get item with min key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - */ - -static PyObject *__pyx_pf_8bintrees_8qbintree_11cBinaryTree_22min_item(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree *__pyx_v_self) { - node_t *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("min_item", 0); - - /* "bintrees\qbintree.pyx":82 - * """ Get item with min key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - * node = ct_min_node(self._root) # <<<<<<<<<<<<<< - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - */ - __pyx_v_node = ct_min_node(__pyx_v_self->_root); - - /* "bintrees\qbintree.pyx":83 - * cdef node_t *node - * node = ct_min_node(self._root) - * if node == NULL: # root is None # <<<<<<<<<<<<<< - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) - */ - __pyx_t_1 = (__pyx_v_node == NULL); - if (__pyx_t_1) { - - /* "bintrees\qbintree.pyx":84 - * node = ct_min_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qbintree.pyx":85 - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_node->key)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_node->value)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value)); - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qbintree.cBinaryTree.min_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_tp_new_8bintrees_8qbintree_cBinaryTree(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - if (__pyx_pw_8bintrees_8qbintree_11cBinaryTree_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8bintrees_8qbintree_cBinaryTree(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8bintrees_8qbintree_11cBinaryTree_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_8bintrees_8qbintree_cBinaryTree[] = { - {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_5count, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_7__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_9__setstate__, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_11clear, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_value"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_13get_value, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_walker"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_15get_walker, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_17insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("remove"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_19remove, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("max_item"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_21max_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qbintree_11cBinaryTree_20max_item)}, - {__Pyx_NAMESTR("min_item"), (PyCFunction)__pyx_pw_8bintrees_8qbintree_11cBinaryTree_23min_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_8qbintree_11cBinaryTree_22min_item)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_cBinaryTree = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_long*/ - #else - 0, /*reserved*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if PY_VERSION_HEX >= 0x02050000 - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_cBinaryTree = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_cBinaryTree = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_cBinaryTree = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -static PyTypeObject __pyx_type_8bintrees_8qbintree_cBinaryTree = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("bintrees.qbintree.cBinaryTree"), /*tp_name*/ - sizeof(struct __pyx_obj_8bintrees_8qbintree_cBinaryTree), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8bintrees_8qbintree_cBinaryTree, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_cBinaryTree, /*tp_as_number*/ - &__pyx_tp_as_sequence_cBinaryTree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_cBinaryTree, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_cBinaryTree, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8bintrees_8qbintree_cBinaryTree, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_8bintrees_8qbintree_cBinaryTree, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("qbintree"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, - {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, - {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__cBinaryTree, __pyx_k__cBinaryTree, sizeof(__pyx_k__cBinaryTree), 0, 0, 1, 1}, - {&__pyx_n_s__cWalker, __pyx_k__cWalker, sizeof(__pyx_k__cWalker), 0, 0, 1, 1}, - {&__pyx_n_s__count, __pyx_k__count, sizeof(__pyx_k__count), 0, 0, 1, 1}, - {&__pyx_n_s__cwalker, __pyx_k__cwalker, sizeof(__pyx_k__cwalker), 0, 0, 1, 1}, - {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1}, - {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1}, - {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1}, - {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1}, - {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "bintrees\qbintree.pyx":60 - * res = ct_bintree_insert(&self._root, key, value) - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<< - * self._count += res - * - */ - __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); - - /* "bintrees\qbintree.pyx":76 - * node = ct_max_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); - - /* "bintrees\qbintree.pyx":84 - * node = ct_min_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initqbintree(void); /*proto*/ -PyMODINIT_FUNC initqbintree(void) -#else -PyMODINIT_FUNC PyInit_qbintree(void); /*proto*/ -PyMODINIT_FUNC PyInit_qbintree(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_qbintree(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("qbintree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "bintrees.qbintree")) { - if (unlikely(PyDict_SetItemString(modules, "bintrees.qbintree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if CYTHON_COMPILING_IN_PYPY - Py_INCREF(__pyx_b); - #endif - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_bintrees__qbintree) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_8bintrees_8qbintree_cBinaryTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "cBinaryTree", (PyObject *)&__pyx_type_8bintrees_8qbintree_cBinaryTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8bintrees_8qbintree_cBinaryTree = &__pyx_type_8bintrees_8qbintree_cBinaryTree; - /*--- Type import code ---*/ - __pyx_ptype_8bintrees_7cwalker_cWalker = __Pyx_ImportType("bintrees.cwalker", "cWalker", sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), 1); if (unlikely(!__pyx_ptype_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_vtabptr_8bintrees_7cwalker_cWalker = (struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker*)__Pyx_GetVtable(__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict); if (unlikely(!__pyx_vtabptr_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Variable import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "bintrees\qbintree.pyx":9 - * # License: MIT License - * - * __all__ = ['cBinaryTree'] # <<<<<<<<<<<<<< - * - * from cwalker import cWalker - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__cBinaryTree)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cBinaryTree)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cBinaryTree)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "bintrees\qbintree.pyx":11 - * __all__ = ['cBinaryTree'] - * - * from cwalker import cWalker # <<<<<<<<<<<<<< - * - * from cwalker cimport * - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__cWalker)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cWalker)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cWalker)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__cwalker), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "bintrees\qbintree.pyx":30 - * - * @property - * def count(self): # <<<<<<<<<<<<<< - * return self._count - * - */ - __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_8qbintree_cBinaryTree, __pyx_n_s__count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_8qbintree_cBinaryTree->tp_dict, __pyx_n_s__count, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_ptype_8bintrees_8qbintree_cBinaryTree); - - /* "bintrees\qbintree.pyx":1 - * #!/usr/bin/env python # <<<<<<<<<<<<<< - * #coding:utf-8 - * # Author: mozman - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - if (__pyx_m) { - __Pyx_AddTraceback("init bintrees.qbintree", __pyx_clineno, __pyx_lineno, __pyx_filename); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init bintrees.qbintree"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif /* CYTHON_REFNANNY */ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != __pyx_b) { - PyErr_Clear(); - result = PyObject_GetAttr(__pyx_b, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AsString(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - continue; - } - name = first_kw_arg; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { - while (*name) { - if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) - && _PyString_Eq(**name, key)) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - if ((**argname == key) || ( - (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) - && _PyString_Eq(**argname, key))) { - goto arg_passed_twice; - } - argname++; - } - } - } else - #endif - if (likely(PyUnicode_Check(key))) { - while (*name) { - int cmp = (**name == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**name, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - int cmp = (**argname == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**argname, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) goto arg_passed_twice; - argname++; - } - } - } else - goto invalid_keyword_type; - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, key); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - Py_XINCREF(type); - if (!value || value == Py_None) - value = NULL; - else - Py_INCREF(value); - if (!tb || tb == Py_None) - tb = NULL; - else { - Py_INCREF(tb); - if (!PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - } - #if PY_VERSION_HEX < 0x02050000 - if (PyClass_Check(type)) { - #else - if (PyType_Check(type)) { - #endif -#if CYTHON_COMPILING_IN_PYPY - if (!value) { - Py_INCREF(Py_None); - value = Py_None; - } -#endif - PyErr_NormalizeException(&type, &value, &tb); - } else { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else /* Python 3+ */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - PyObject* owned_instance = NULL; - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } - else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; - } - } else { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause && cause != Py_None) { - PyObject *fixed_cause; - if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } - else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } - else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } -bad: - Py_XDECREF(owned_instance); - return; -} -#endif - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { - PyObject *py_import = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!py_import) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - #if PY_VERSION_HEX >= 0x02050000 - { - #if PY_MAJOR_VERSION >= 3 - if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { - /* try package relative import first */ - PyObject *py_level = PyInt_FromLong(1); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - if (!module) { - if (!PyErr_ExceptionMatches(PyExc_ImportError)) - goto bad; - PyErr_Clear(); - } - } - level = 0; /* try absolute import on failure */ - } - #endif - if (!module) { - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - } - } - #else - if (level>0) { - PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); - goto bad; - } - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); - #endif -bad: - Py_XDECREF(empty_list); - Py_XDECREF(py_import); - Py_XDECREF(empty_dict); - return module; -} - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)PyLong_AsUnsignedLong(x); - } else { - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static int __Pyx_check_binary_version(void) { - char ctversion[4], rtversion[4]; - PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); - PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); - if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { - char message[200]; - PyOS_snprintf(message, sizeof(message), - "compiletime version %s of module '%.100s' " - "does not match runtime version %s", - ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else - return PyErr_WarnEx(NULL, message, 1); - #endif - } - return 0; -} - -#ifndef __PYX_HAVE_RT_ImportModule -#define __PYX_HAVE_RT_ImportModule -static PyObject *__Pyx_ImportModule(const char *name) { - PyObject *py_name = 0; - PyObject *py_module = 0; - py_name = __Pyx_PyIdentifier_FromString(name); - if (!py_name) - goto bad; - py_module = PyImport_Import(py_name); - Py_DECREF(py_name); - return py_module; -bad: - Py_XDECREF(py_name); - return 0; -} -#endif - -#ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, - size_t size, int strict) -{ - PyObject *py_module = 0; - PyObject *result = 0; - PyObject *py_name = 0; - char warning[200]; - py_module = __Pyx_ImportModule(module_name); - if (!py_module) - goto bad; - py_name = __Pyx_PyIdentifier_FromString(class_name); - if (!py_name) - goto bad; - result = PyObject_GetAttr(py_module, py_name); - Py_DECREF(py_name); - py_name = 0; - Py_DECREF(py_module); - py_module = 0; - if (!result) - goto bad; - if (!PyType_Check(result)) { - PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", - module_name, class_name); - goto bad; - } - if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility", - module_name, class_name); - #if PY_VERSION_HEX < 0x02050000 - if (PyErr_Warn(NULL, warning) < 0) goto bad; - #else - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - #endif - } - else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", - module_name, class_name); - goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(py_module); - Py_XDECREF(result); - return NULL; -} -#endif - -static void* __Pyx_GetVtable(PyObject *dict) { - void* ptr; - PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); - if (!ob) - goto bad; -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - ptr = PyCapsule_GetPointer(ob, 0); -#else - ptr = PyCObject_AsVoidPtr(ob); -#endif - if (!ptr && !PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); - Py_DECREF(ob); - return ptr; -bad: - Py_XDECREF(ob); - return NULL; -} - -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */
diff --git a/third_party/bintrees/bintrees/qbintree.pyx b/third_party/bintrees/bintrees/qbintree.pyx deleted file mode 100644 index 01d129f..0000000 --- a/third_party/bintrees/bintrees/qbintree.pyx +++ /dev/null
@@ -1,85 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: cython unbalanced binary tree module -# Created: 28.04.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -__all__ = ['cBinaryTree'] - -from cwalker import cWalker - -from cwalker cimport * -from ctrees cimport * - -cdef class cBinaryTree: - cdef node_t *_root - cdef int _count - - def __cinit__(self, items=None): - self._root = NULL - self._count = 0 - if items: - self.update(items) - - def __dealloc__(self): - ct_delete_tree(self._root) - - @property - def count(self): - return self._count - - def __getstate__(self): - return dict(self.items()) - - def __setstate__(self, state): - self.update(state) - - def clear(self): - ct_delete_tree(self._root) - self._count = 0 - self._root = NULL - - def get_value(self, key): - result = <object> ct_get_item(self._root, key) - if result is None: - raise KeyError(key) - else: - return result[1] - - def get_walker(self): - cdef cWalker walker - walker = cWalker() - walker.set_tree(self._root) - return walker - - def insert(self, key, value): - res = ct_bintree_insert(&self._root, key, value) - if res < 0: - raise MemoryError('Can not allocate memory for node structure.') - self._count += res - - def remove(self, key): - cdef int result - result = ct_bintree_remove(&self._root, key) - if result == 0: - raise KeyError(str(key)) - else: - self._count -= 1 - - def max_item(self): - """ Get item with max key of tree, raises ValueError if tree is empty. """ - cdef node_t *node - node = ct_max_node(self._root) - if node == NULL: # root is None - raise ValueError("Tree is empty") - return (<object>node.key, <object>node.value) - - def min_item(self): - """ Get item with min key of tree, raises ValueError if tree is empty. """ - cdef node_t *node - node = ct_min_node(self._root) - if node == NULL: # root is None - raise ValueError("Tree is empty") - return (<object>node.key, <object>node.value)
diff --git a/third_party/bintrees/bintrees/qrbtree.c b/third_party/bintrees/bintrees/qrbtree.c deleted file mode 100644 index f5aa162..0000000 --- a/third_party/bintrees/bintrees/qrbtree.c +++ /dev/null
@@ -1,3399 +0,0 @@ -/* Generated by Cython 0.17.4 on Sun Feb 24 19:48:34 2013 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. -#else -#include <stddef.h> /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef Py_HUGE_VAL - #define Py_HUGE_VAL HUGE_VAL -#endif -#ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 -#else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define CYTHON_FORMAT_SSIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ - (PyErr_Format(PyExc_TypeError, \ - "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ - (PyObject*)0)) - #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \ - !PyComplex_Check(o)) - #define PyIndex_Check __Pyx_PyIndex_Check - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" - #define CYTHON_FORMAT_SSIZE_T "z" - #define __Pyx_PyIndex_Check PyIndex_Check -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#endif -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) - #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ - 0 : _PyUnicode_Ready((PyObject *)(op))) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) - #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) -#else - #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_READY(op) (0) - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) - #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif -#ifndef PySet_CheckExact - #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) -#if PY_MAJOR_VERSION >= 3 - #define PyIntObject PyLongObject - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBoolObject PyLongObject -#endif -#if PY_VERSION_HEX < 0x03020000 - typedef long Py_hash_t; - #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong -#else - #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t -#endif -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#ifndef __PYX_EXTERN_C - #ifdef __cplusplus - #define __PYX_EXTERN_C extern "C" - #else - #define __PYX_EXTERN_C extern - #endif -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include <math.h> -#define __PYX_HAVE__bintrees__qrbtree -#define __PYX_HAVE_API__bintrees__qrbtree -#include "ctrees.h" -#include "stack.h" -#ifdef _OPENMP -#include <omp.h> -#endif /* _OPENMP */ - -#ifdef PYREX_WITHOUT_ASSERTIONS -#define CYTHON_WITHOUT_ASSERTIONS -#endif - - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#if CYTHON_COMPILING_IN_CPYTHON -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) -#else -#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) -#endif -#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) - -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ - #define likely(x) (x) - #define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -static const char *__pyx_f[] = { - "qrbtree.pyx", - "cwalker.pxd", -}; - -/*--- Type declarations ---*/ -struct __pyx_obj_8bintrees_7cwalker_cWalker; -struct __pyx_obj_8bintrees_7qrbtree_cRBTree; - -/* "cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ -struct __pyx_obj_8bintrees_7cwalker_cWalker { - PyObject_HEAD - struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtab; - node_t *node; - node_t *root; - node_stack_t *stack; -}; - - -/* "bintrees\qrbtree.pyx":16 - * from ctrees cimport * - * - * cdef class cRBTree: # <<<<<<<<<<<<<< - * cdef node_t *_root - * cdef int _count - */ -struct __pyx_obj_8bintrees_7qrbtree_cRBTree { - PyObject_HEAD - node_t *_root; - int _count; -}; - - - -/* "cwalker.pxd":11 - * from stack cimport node_stack_t - * - * cdef class cWalker: # <<<<<<<<<<<<<< - * cdef node_t *node - * cdef node_t *root - */ - -struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker { - void (*set_tree)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, node_t *); - PyObject *(*reset)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*push)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); - PyObject *(*pop)(struct __pyx_obj_8bintrees_7cwalker_cWalker *, int __pyx_skip_dispatch); -}; -static struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *__pyx_vtabptr_8bintrees_7cwalker_cWalker; -#ifndef CYTHON_REFNANNY - #define CYTHON_REFNANNY 0 -#endif -#if CYTHON_REFNANNY - typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*SetupContext)(const char*, int, const char*); - void (*FinishContext)(void**); - } __Pyx_RefNannyAPIStruct; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ - #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; -#ifdef WITH_THREAD - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - if (acquire_gil) { \ - PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - } -#else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) -#endif - #define __Pyx_RefNannyFinishContext() \ - __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) - #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) - #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) -#else - #define __Pyx_RefNannyDeclarations - #define __Pyx_RefNannySetupContext(name, acquire_gil) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XINCREF(r) Py_XINCREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) - #define __Pyx_XGOTREF(r) - #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) -#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ - const char* function_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { -#if CYTHON_COMPILING_IN_CPYTHON - if (PyList_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { /* inlined PySequence_GetItem() */ - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (unlikely(l < 0)) return NULL; - i += l; - } - return m->sq_item(o, i); - } - } -#else - if (PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static int __Pyx_check_binary_version(void); - -#if !defined(__Pyx_PyIdentifier_FromString) -#if PY_MAJOR_VERSION < 3 - #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) -#else - #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) -#endif -#endif - -static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ - -static void* __Pyx_GetVtable(PyObject *dict); /*proto*/ - -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - - -/* Module declarations from 'bintrees.ctrees' */ - -/* Module declarations from 'bintrees.stack' */ - -/* Module declarations from 'bintrees.cwalker' */ -static PyTypeObject *__pyx_ptype_8bintrees_7cwalker_cWalker = 0; - -/* Module declarations from 'bintrees.qrbtree' */ -static PyTypeObject *__pyx_ptype_8bintrees_7qrbtree_cRBTree = 0; -#define __Pyx_MODULE_NAME "bintrees.qrbtree" -int __pyx_module_is_main_bintrees__qrbtree = 0; - -/* Implementation of 'bintrees.qrbtree' */ -static PyObject *__pyx_builtin_property; -static PyObject *__pyx_builtin_KeyError; -static PyObject *__pyx_builtin_MemoryError; -static PyObject *__pyx_builtin_ValueError; -static int __pyx_pf_8bintrees_7qrbtree_7cRBTree___cinit__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_items); /* proto */ -static void __pyx_pf_8bintrees_7qrbtree_7cRBTree_2__dealloc__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_4count(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_6__getstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_8__setstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_state); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_10clear(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_12get_value(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_14get_walker(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_16insert(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_18remove(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_20max_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_22min_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self); /* proto */ -static char __pyx_k_1[] = "Can not allocate memory for node structure."; -static char __pyx_k_3[] = "Tree is empty"; -static char __pyx_k__key[] = "key"; -static char __pyx_k__count[] = "count"; -static char __pyx_k__items[] = "items"; -static char __pyx_k__value[] = "value"; -static char __pyx_k__update[] = "update"; -static char __pyx_k____all__[] = "__all__"; -static char __pyx_k__cRBTree[] = "cRBTree"; -static char __pyx_k__cWalker[] = "cWalker"; -static char __pyx_k__cwalker[] = "cwalker"; -static char __pyx_k__KeyError[] = "KeyError"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k__property[] = "property"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__MemoryError[] = "MemoryError"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_kp_s_3; -static PyObject *__pyx_n_s__KeyError; -static PyObject *__pyx_n_s__MemoryError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____all__; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s__cRBTree; -static PyObject *__pyx_n_s__cWalker; -static PyObject *__pyx_n_s__count; -static PyObject *__pyx_n_s__cwalker; -static PyObject *__pyx_n_s__items; -static PyObject *__pyx_n_s__key; -static PyObject *__pyx_n_s__property; -static PyObject *__pyx_n_s__update; -static PyObject *__pyx_n_s__value; -static PyObject *__pyx_int_0; -static PyObject *__pyx_k_tuple_2; -static PyObject *__pyx_k_tuple_4; -static PyObject *__pyx_k_tuple_5; - -/* Python wrapper */ -static int __pyx_pw_8bintrees_7qrbtree_7cRBTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8bintrees_7qrbtree_7cRBTree_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_items = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__items,0}; - PyObject* values[1] = {0}; - - /* "bintrees\qrbtree.pyx":20 - * cdef int _count - * - * def __cinit__(self, items=None): # <<<<<<<<<<<<<< - * self._root = NULL - * self._count = 0 - */ - values[0] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__items); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_items = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree___cinit__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), __pyx_v_items); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8bintrees_7qrbtree_7cRBTree___cinit__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_items) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "bintrees\qrbtree.pyx":21 - * - * def __cinit__(self, items=None): - * self._root = NULL # <<<<<<<<<<<<<< - * self._count = 0 - * if items: - */ - __pyx_v_self->_root = NULL; - - /* "bintrees\qrbtree.pyx":22 - * def __cinit__(self, items=None): - * self._root = NULL - * self._count = 0 # <<<<<<<<<<<<<< - * if items: - * self.update(items) - */ - __pyx_v_self->_count = 0; - - /* "bintrees\qrbtree.pyx":23 - * self._root = NULL - * self._count = 0 - * if items: # <<<<<<<<<<<<<< - * self.update(items) - * - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_items); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "bintrees\qrbtree.pyx":24 - * self._count = 0 - * if items: - * self.update(items) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_items); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_items); - __Pyx_GIVEREF(__pyx_v_items); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8bintrees_7qrbtree_7cRBTree_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8bintrees_7qrbtree_7cRBTree_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8bintrees_7qrbtree_7cRBTree_2__dealloc__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "bintrees\qrbtree.pyx":26 - * self.update(items) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * ct_delete_tree(self._root) - * - */ - -static void __pyx_pf_8bintrees_7qrbtree_7cRBTree_2__dealloc__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "bintrees\qrbtree.pyx":27 - * - * def __dealloc__(self): - * ct_delete_tree(self._root) # <<<<<<<<<<<<<< - * - * @property - */ - ct_delete_tree(__pyx_v_self->_root); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_5count(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("count (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_4count(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":30 - * - * @property - * def count(self): # <<<<<<<<<<<<<< - * return self._count - * - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_4count(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("count", 0); - - /* "bintrees\qrbtree.pyx":31 - * @property - * def count(self): - * return self._count # <<<<<<<<<<<<<< - * - * def __getstate__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.count", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_7__getstate__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getstate__ (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_6__getstate__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":33 - * return self._count - * - * def __getstate__(self): # <<<<<<<<<<<<<< - * return dict(self.items()) - * - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_6__getstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getstate__", 0); - - /* "bintrees\qrbtree.pyx":34 - * - * def __getstate__(self): - * return dict(self.items()) # <<<<<<<<<<<<<< - * - * def __setstate__(self, state): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__getstate__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_9__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_8__setstate__(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), ((PyObject *)__pyx_v_state)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":36 - * return dict(self.items()) - * - * def __setstate__(self, state): # <<<<<<<<<<<<<< - * self.update(state) - * - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_8__setstate__(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_state) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setstate__", 0); - - /* "bintrees\qrbtree.pyx":37 - * - * def __setstate__(self, state): - * self.update(state) # <<<<<<<<<<<<<< - * - * def clear(self): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__update); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_state); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_state); - __Pyx_GIVEREF(__pyx_v_state); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_11clear(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_10clear(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":39 - * self.update(state) - * - * def clear(self): # <<<<<<<<<<<<<< - * ct_delete_tree(self._root) - * self._count = 0 - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_10clear(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clear", 0); - - /* "bintrees\qrbtree.pyx":40 - * - * def clear(self): - * ct_delete_tree(self._root) # <<<<<<<<<<<<<< - * self._count = 0 - * self._root = NULL - */ - ct_delete_tree(__pyx_v_self->_root); - - /* "bintrees\qrbtree.pyx":41 - * def clear(self): - * ct_delete_tree(self._root) - * self._count = 0 # <<<<<<<<<<<<<< - * self._root = NULL - * - */ - __pyx_v_self->_count = 0; - - /* "bintrees\qrbtree.pyx":42 - * ct_delete_tree(self._root) - * self._count = 0 - * self._root = NULL # <<<<<<<<<<<<<< - * - * def get_value(self, key): - */ - __pyx_v_self->_root = NULL; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_13get_value(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_value (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_12get_value(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":44 - * self._root = NULL - * - * def get_value(self, key): # <<<<<<<<<<<<<< - * result = <object> ct_get_item(self._root, key) - * if result is None: - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_12get_value(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_value", 0); - - /* "bintrees\qrbtree.pyx":45 - * - * def get_value(self, key): - * result = <object> ct_get_item(self._root, key) # <<<<<<<<<<<<<< - * if result is None: - * raise KeyError(key) - */ - __pyx_t_1 = ct_get_item(__pyx_v_self->_root, __pyx_v_key); - __Pyx_INCREF(((PyObject *)__pyx_t_1)); - __pyx_v_result = ((PyObject *)__pyx_t_1); - - /* "bintrees\qrbtree.pyx":46 - * def get_value(self, key): - * result = <object> ct_get_item(self._root, key) - * if result is None: # <<<<<<<<<<<<<< - * raise KeyError(key) - * else: - */ - __pyx_t_2 = (__pyx_v_result == Py_None); - if (__pyx_t_2) { - - /* "bintrees\qrbtree.pyx":47 - * result = <object> ct_get_item(self._root, key) - * if result is None: - * raise KeyError(key) # <<<<<<<<<<<<<< - * else: - * return result[1] - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_4 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qrbtree.pyx":49 - * raise KeyError(key) - * else: - * return result[1] # <<<<<<<<<<<<<< - * - * def get_walker(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_result, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_15get_walker(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_walker (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_14get_walker(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":51 - * return result[1] - * - * def get_walker(self): # <<<<<<<<<<<<<< - * cdef cWalker walker - * walker = cWalker() - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_14get_walker(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - struct __pyx_obj_8bintrees_7cwalker_cWalker *__pyx_v_walker = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_walker", 0); - - /* "bintrees\qrbtree.pyx":53 - * def get_walker(self): - * cdef cWalker walker - * walker = cWalker() # <<<<<<<<<<<<<< - * walker.set_tree(self._root) - * return walker - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8bintrees_7cwalker_cWalker)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_walker = ((struct __pyx_obj_8bintrees_7cwalker_cWalker *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "bintrees\qrbtree.pyx":54 - * cdef cWalker walker - * walker = cWalker() - * walker.set_tree(self._root) # <<<<<<<<<<<<<< - * return walker - * - */ - ((struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker *)__pyx_v_walker->__pyx_vtab)->set_tree(__pyx_v_walker, __pyx_v_self->_root); - - /* "bintrees\qrbtree.pyx":55 - * walker = cWalker() - * walker.set_tree(self._root) - * return walker # <<<<<<<<<<<<<< - * - * def insert(self, key, value): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_walker)); - __pyx_r = ((PyObject *)__pyx_v_walker); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.get_walker", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_walker); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_17insert(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_key = 0; - PyObject *__pyx_v_value = 0; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("insert (wrapper)", 0); - { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__key,&__pyx_n_s__value,0}; - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__key)) != 0)) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__value)) != 0)) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "insert") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_key = values[0]; - __pyx_v_value = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("insert", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_16insert(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), __pyx_v_key, __pyx_v_value); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":57 - * return walker - * - * def insert(self, key, value): # <<<<<<<<<<<<<< - * res = rb_insert(&self._root, key, value) - * if res < 0: - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_16insert(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) { - PyObject *__pyx_v_res = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("insert", 0); - - /* "bintrees\qrbtree.pyx":58 - * - * def insert(self, key, value): - * res = rb_insert(&self._root, key, value) # <<<<<<<<<<<<<< - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') - */ - __pyx_t_1 = PyInt_FromLong(rb_insert((&__pyx_v_self->_root), __pyx_v_key, __pyx_v_value)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_res = __pyx_t_1; - __pyx_t_1 = 0; - - /* "bintrees\qrbtree.pyx":59 - * def insert(self, key, value): - * res = rb_insert(&self._root, key, value) - * if res < 0: # <<<<<<<<<<<<<< - * raise MemoryError('Can not allocate memory for node structure.') - * else: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_res, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "bintrees\qrbtree.pyx":60 - * res = rb_insert(&self._root, key, value) - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<< - * else: - * self._count += res - */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qrbtree.pyx":62 - * raise MemoryError('Can not allocate memory for node structure.') - * else: - * self._count += res # <<<<<<<<<<<<<< - * - * def remove(self, key): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_res); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_self->_count = __pyx_t_4; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_res); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_19remove(PyObject *__pyx_v_self, PyObject *__pyx_v_key) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("remove (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_18remove(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self), ((PyObject *)__pyx_v_key)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":64 - * self._count += res - * - * def remove(self, key): # <<<<<<<<<<<<<< - * cdef int result - * result = rb_remove(&self._root, key) - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_18remove(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self, PyObject *__pyx_v_key) { - int __pyx_v_result; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("remove", 0); - - /* "bintrees\qrbtree.pyx":66 - * def remove(self, key): - * cdef int result - * result = rb_remove(&self._root, key) # <<<<<<<<<<<<<< - * if result == 0: - * raise KeyError(str(key)) - */ - __pyx_v_result = rb_remove((&__pyx_v_self->_root), __pyx_v_key); - - /* "bintrees\qrbtree.pyx":67 - * cdef int result - * result = rb_remove(&self._root, key) - * if result == 0: # <<<<<<<<<<<<<< - * raise KeyError(str(key)) - * else: - */ - __pyx_t_1 = (__pyx_v_result == 0); - if (__pyx_t_1) { - - /* "bintrees\qrbtree.pyx":68 - * result = rb_remove(&self._root, key) - * if result == 0: - * raise KeyError(str(key)) # <<<<<<<<<<<<<< - * else: - * self._count -= 1 - */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key); - __Pyx_GIVEREF(__pyx_v_key); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - /*else*/ { - - /* "bintrees\qrbtree.pyx":70 - * raise KeyError(str(key)) - * else: - * self._count -= 1 # <<<<<<<<<<<<<< - * - * def max_item(self): - */ - __pyx_v_self->_count = (__pyx_v_self->_count - 1); - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.remove", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_7qrbtree_7cRBTree_20max_item[] = " Get item with max key of tree, raises ValueError if tree is empty. "; -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_21max_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("max_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_20max_item(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":72 - * self._count -= 1 - * - * def max_item(self): # <<<<<<<<<<<<<< - * """ Get item with max key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_20max_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - node_t *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("max_item", 0); - - /* "bintrees\qrbtree.pyx":75 - * """ Get item with max key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - * node = ct_max_node(self._root) # <<<<<<<<<<<<<< - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - */ - __pyx_v_node = ct_max_node(__pyx_v_self->_root); - - /* "bintrees\qrbtree.pyx":76 - * cdef node_t *node - * node = ct_max_node(self._root) - * if node == NULL: # root is None # <<<<<<<<<<<<<< - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) - */ - __pyx_t_1 = (__pyx_v_node == NULL); - if (__pyx_t_1) { - - /* "bintrees\qrbtree.pyx":77 - * node = ct_max_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qrbtree.pyx":78 - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<< - * - * def min_item(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_node->key)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_node->value)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value)); - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.max_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8bintrees_7qrbtree_7cRBTree_22min_item[] = " Get item with min key of tree, raises ValueError if tree is empty. "; -static PyObject *__pyx_pw_8bintrees_7qrbtree_7cRBTree_23min_item(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("min_item (wrapper)", 0); - __pyx_r = __pyx_pf_8bintrees_7qrbtree_7cRBTree_22min_item(((struct __pyx_obj_8bintrees_7qrbtree_cRBTree *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "bintrees\qrbtree.pyx":80 - * return (<object>node.key, <object>node.value) - * - * def min_item(self): # <<<<<<<<<<<<<< - * """ Get item with min key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - */ - -static PyObject *__pyx_pf_8bintrees_7qrbtree_7cRBTree_22min_item(struct __pyx_obj_8bintrees_7qrbtree_cRBTree *__pyx_v_self) { - node_t *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("min_item", 0); - - /* "bintrees\qrbtree.pyx":83 - * """ Get item with min key of tree, raises ValueError if tree is empty. """ - * cdef node_t *node - * node = ct_min_node(self._root) # <<<<<<<<<<<<<< - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - */ - __pyx_v_node = ct_min_node(__pyx_v_self->_root); - - /* "bintrees\qrbtree.pyx":84 - * cdef node_t *node - * node = ct_min_node(self._root) - * if node == NULL: # root is None # <<<<<<<<<<<<<< - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) - */ - __pyx_t_1 = (__pyx_v_node == NULL); - if (__pyx_t_1) { - - /* "bintrees\qrbtree.pyx":85 - * node = ct_min_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "bintrees\qrbtree.pyx":86 - * if node == NULL: # root is None - * raise ValueError("Tree is empty") - * return (<object>node.key, <object>node.value) # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_node->key)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_node->key)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->key)); - __Pyx_INCREF(((PyObject *)__pyx_v_node->value)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_node->value)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_node->value)); - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("bintrees.qrbtree.cRBTree.min_item", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_tp_new_8bintrees_7qrbtree_cRBTree(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - if (__pyx_pw_8bintrees_7qrbtree_7cRBTree_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8bintrees_7qrbtree_cRBTree(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8bintrees_7qrbtree_7cRBTree_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_8bintrees_7qrbtree_cRBTree[] = { - {__Pyx_NAMESTR("count"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_5count, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("__getstate__"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_7__getstate__, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("__setstate__"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_9__setstate__, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("clear"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_11clear, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_value"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_13get_value, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_walker"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_15get_walker, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_17insert, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("remove"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_19remove, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("max_item"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_21max_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_7qrbtree_7cRBTree_20max_item)}, - {__Pyx_NAMESTR("min_item"), (PyCFunction)__pyx_pw_8bintrees_7qrbtree_7cRBTree_23min_item, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8bintrees_7qrbtree_7cRBTree_22min_item)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_cRBTree = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_long*/ - #else - 0, /*reserved*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if PY_VERSION_HEX >= 0x02050000 - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_cRBTree = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_cRBTree = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_cRBTree = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -static PyTypeObject __pyx_type_8bintrees_7qrbtree_cRBTree = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("bintrees.qrbtree.cRBTree"), /*tp_name*/ - sizeof(struct __pyx_obj_8bintrees_7qrbtree_cRBTree), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8bintrees_7qrbtree_cRBTree, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_cRBTree, /*tp_as_number*/ - &__pyx_tp_as_sequence_cRBTree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_cRBTree, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_cRBTree, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8bintrees_7qrbtree_cRBTree, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_8bintrees_7qrbtree_cRBTree, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ - #endif -}; - -static PyMethodDef __pyx_methods[] = { - {0, 0, 0, 0} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("qrbtree"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, - {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, - {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____all__, __pyx_k____all__, sizeof(__pyx_k____all__), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s__cRBTree, __pyx_k__cRBTree, sizeof(__pyx_k__cRBTree), 0, 0, 1, 1}, - {&__pyx_n_s__cWalker, __pyx_k__cWalker, sizeof(__pyx_k__cWalker), 0, 0, 1, 1}, - {&__pyx_n_s__count, __pyx_k__count, sizeof(__pyx_k__count), 0, 0, 1, 1}, - {&__pyx_n_s__cwalker, __pyx_k__cwalker, sizeof(__pyx_k__cwalker), 0, 0, 1, 1}, - {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1}, - {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1}, - {&__pyx_n_s__property, __pyx_k__property, sizeof(__pyx_k__property), 0, 0, 1, 1}, - {&__pyx_n_s__update, __pyx_k__update, sizeof(__pyx_k__update), 0, 0, 1, 1}, - {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_property = __Pyx_GetName(__pyx_b, __pyx_n_s__property); if (!__pyx_builtin_property) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "bintrees\qrbtree.pyx":60 - * res = rb_insert(&self._root, key, value) - * if res < 0: - * raise MemoryError('Can not allocate memory for node structure.') # <<<<<<<<<<<<<< - * else: - * self._count += res - */ - __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); - PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); - - /* "bintrees\qrbtree.pyx":77 - * node = ct_max_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - * - */ - __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); - - /* "bintrees\qrbtree.pyx":85 - * node = ct_min_node(self._root) - * if node == NULL: # root is None - * raise ValueError("Tree is empty") # <<<<<<<<<<<<<< - * return (<object>node.key, <object>node.value) - */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initqrbtree(void); /*proto*/ -PyMODINIT_FUNC initqrbtree(void) -#else -PyMODINIT_FUNC PyInit_qrbtree(void); /*proto*/ -PyMODINIT_FUNC PyInit_qrbtree(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_qrbtree(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("qrbtree"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if PY_MAJOR_VERSION >= 3 - { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "bintrees.qrbtree")) { - if (unlikely(PyDict_SetItemString(modules, "bintrees.qrbtree", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if CYTHON_COMPILING_IN_PYPY - Py_INCREF(__pyx_b); - #endif - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main_bintrees__qrbtree) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_8bintrees_7qrbtree_cRBTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "cRBTree", (PyObject *)&__pyx_type_8bintrees_7qrbtree_cRBTree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8bintrees_7qrbtree_cRBTree = &__pyx_type_8bintrees_7qrbtree_cRBTree; - /*--- Type import code ---*/ - __pyx_ptype_8bintrees_7cwalker_cWalker = __Pyx_ImportType("bintrees.cwalker", "cWalker", sizeof(struct __pyx_obj_8bintrees_7cwalker_cWalker), 1); if (unlikely(!__pyx_ptype_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_vtabptr_8bintrees_7cwalker_cWalker = (struct __pyx_vtabstruct_8bintrees_7cwalker_cWalker*)__Pyx_GetVtable(__pyx_ptype_8bintrees_7cwalker_cWalker->tp_dict); if (unlikely(!__pyx_vtabptr_8bintrees_7cwalker_cWalker)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Variable import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "bintrees\qrbtree.pyx":9 - * # License: MIT License - * - * __all__ = ['cRBTree'] # <<<<<<<<<<<<<< - * - * from cwalker import cWalker - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__cRBTree)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cRBTree)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cRBTree)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____all__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - - /* "bintrees\qrbtree.pyx":11 - * __all__ = ['cRBTree'] - * - * from cwalker import cWalker # <<<<<<<<<<<<<< - * - * from cwalker cimport * - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__cWalker)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__cWalker)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__cWalker)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__cwalker), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "bintrees\qrbtree.pyx":30 - * - * @property - * def count(self): # <<<<<<<<<<<<<< - * return self._count - * - */ - __pyx_t_2 = __Pyx_GetName((PyObject *)__pyx_ptype_8bintrees_7qrbtree_cRBTree, __pyx_n_s__count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_property, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_8bintrees_7qrbtree_cRBTree->tp_dict, __pyx_n_s__count, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_ptype_8bintrees_7qrbtree_cRBTree); - - /* "bintrees\qrbtree.pyx":1 - * #!/usr/bin/env python # <<<<<<<<<<<<<< - * #coding:utf-8 - * # Author: mozman - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - if (__pyx_m) { - __Pyx_AddTraceback("init bintrees.qrbtree", __pyx_clineno, __pyx_lineno, __pyx_filename); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init bintrees.qrbtree"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif /* CYTHON_REFNANNY */ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != __pyx_b) { - PyErr_Clear(); - result = PyObject_GetAttr(__pyx_b, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AsString(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - continue; - } - name = first_kw_arg; - #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { - while (*name) { - if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) - && _PyString_Eq(**name, key)) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - if ((**argname == key) || ( - (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) - && _PyString_Eq(**argname, key))) { - goto arg_passed_twice; - } - argname++; - } - } - } else - #endif - if (likely(PyUnicode_Check(key))) { - while (*name) { - int cmp = (**name == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**name, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) { - values[name-argnames] = value; - break; - } - name++; - } - if (*name) continue; - else { - PyObject*** argname = argnames; - while (argname != first_kw_arg) { - int cmp = (**argname == key) ? 0 : - #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : - #endif - PyUnicode_Compare(**argname, key); - if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; - if (cmp == 0) goto arg_passed_twice; - argname++; - } - } - } else - goto invalid_keyword_type; - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, key); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - Py_XINCREF(type); - if (!value || value == Py_None) - value = NULL; - else - Py_INCREF(value); - if (!tb || tb == Py_None) - tb = NULL; - else { - Py_INCREF(tb); - if (!PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - } - #if PY_VERSION_HEX < 0x02050000 - if (PyClass_Check(type)) { - #else - if (PyType_Check(type)) { - #endif -#if CYTHON_COMPILING_IN_PYPY - if (!value) { - Py_INCREF(Py_None); - value = Py_None; - } -#endif - PyErr_NormalizeException(&type, &value, &tb); - } else { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else /* Python 3+ */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - PyObject* owned_instance = NULL; - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (PyExceptionClass_Check(type)) { - PyObject *args; - if (!value) - args = PyTuple_New(0); - else if (PyTuple_Check(value)) { - Py_INCREF(value); - args = value; - } - else - args = PyTuple_Pack(1, value); - if (!args) - goto bad; - owned_instance = PyEval_CallObject(type, args); - Py_DECREF(args); - if (!owned_instance) - goto bad; - value = owned_instance; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto bad; - } - } else { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause && cause != Py_None) { - PyObject *fixed_cause; - if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } - else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } - else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } -bad: - Py_XDECREF(owned_instance); - return; -} -#endif - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { - PyObject *py_import = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!py_import) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - #if PY_VERSION_HEX >= 0x02050000 - { - #if PY_MAJOR_VERSION >= 3 - if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { - /* try package relative import first */ - PyObject *py_level = PyInt_FromLong(1); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - if (!module) { - if (!PyErr_ExceptionMatches(PyExc_ImportError)) - goto bad; - PyErr_Clear(); - } - } - level = 0; /* try absolute import on failure */ - } - #endif - if (!module) { - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - } - } - #else - if (level>0) { - PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); - goto bad; - } - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); - #endif -bad: - Py_XDECREF(empty_list); - Py_XDECREF(py_import); - Py_XDECREF(empty_dict); - return module; -} - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)PyLong_AsUnsignedLong(x); - } else { - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static int __Pyx_check_binary_version(void) { - char ctversion[4], rtversion[4]; - PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); - PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); - if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { - char message[200]; - PyOS_snprintf(message, sizeof(message), - "compiletime version %s of module '%.100s' " - "does not match runtime version %s", - ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else - return PyErr_WarnEx(NULL, message, 1); - #endif - } - return 0; -} - -#ifndef __PYX_HAVE_RT_ImportModule -#define __PYX_HAVE_RT_ImportModule -static PyObject *__Pyx_ImportModule(const char *name) { - PyObject *py_name = 0; - PyObject *py_module = 0; - py_name = __Pyx_PyIdentifier_FromString(name); - if (!py_name) - goto bad; - py_module = PyImport_Import(py_name); - Py_DECREF(py_name); - return py_module; -bad: - Py_XDECREF(py_name); - return 0; -} -#endif - -#ifndef __PYX_HAVE_RT_ImportType -#define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, - size_t size, int strict) -{ - PyObject *py_module = 0; - PyObject *result = 0; - PyObject *py_name = 0; - char warning[200]; - py_module = __Pyx_ImportModule(module_name); - if (!py_module) - goto bad; - py_name = __Pyx_PyIdentifier_FromString(class_name); - if (!py_name) - goto bad; - result = PyObject_GetAttr(py_module, py_name); - Py_DECREF(py_name); - py_name = 0; - Py_DECREF(py_module); - py_module = 0; - if (!result) - goto bad; - if (!PyType_Check(result)) { - PyErr_Format(PyExc_TypeError, - "%s.%s is not a type object", - module_name, class_name); - goto bad; - } - if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility", - module_name, class_name); - #if PY_VERSION_HEX < 0x02050000 - if (PyErr_Warn(NULL, warning) < 0) goto bad; - #else - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - #endif - } - else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%s.%s has the wrong size, try recompiling", - module_name, class_name); - goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(py_module); - Py_XDECREF(result); - return NULL; -} -#endif - -static void* __Pyx_GetVtable(PyObject *dict) { - void* ptr; - PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); - if (!ob) - goto bad; -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - ptr = PyCapsule_GetPointer(ob, 0); -#else - ptr = PyCObject_AsVoidPtr(ob); -#endif - if (!ptr && !PyErr_Occurred()) - PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); - Py_DECREF(ob); - return ptr; -bad: - Py_XDECREF(ob); - return NULL; -} - -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */
diff --git a/third_party/bintrees/bintrees/qrbtree.pyx b/third_party/bintrees/bintrees/qrbtree.pyx deleted file mode 100644 index f7f1dcf..0000000 --- a/third_party/bintrees/bintrees/qrbtree.pyx +++ /dev/null
@@ -1,86 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: cython unbalanced binary tree module -# Created: 28.04.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -__all__ = ['cRBTree'] - -from cwalker import cWalker - -from cwalker cimport * -from ctrees cimport * - -cdef class cRBTree: - cdef node_t *_root - cdef int _count - - def __cinit__(self, items=None): - self._root = NULL - self._count = 0 - if items: - self.update(items) - - def __dealloc__(self): - ct_delete_tree(self._root) - - @property - def count(self): - return self._count - - def __getstate__(self): - return dict(self.items()) - - def __setstate__(self, state): - self.update(state) - - def clear(self): - ct_delete_tree(self._root) - self._count = 0 - self._root = NULL - - def get_value(self, key): - result = <object> ct_get_item(self._root, key) - if result is None: - raise KeyError(key) - else: - return result[1] - - def get_walker(self): - cdef cWalker walker - walker = cWalker() - walker.set_tree(self._root) - return walker - - def insert(self, key, value): - res = rb_insert(&self._root, key, value) - if res < 0: - raise MemoryError('Can not allocate memory for node structure.') - else: - self._count += res - - def remove(self, key): - cdef int result - result = rb_remove(&self._root, key) - if result == 0: - raise KeyError(str(key)) - else: - self._count -= 1 - - def max_item(self): - """ Get item with max key of tree, raises ValueError if tree is empty. """ - cdef node_t *node - node = ct_max_node(self._root) - if node == NULL: # root is None - raise ValueError("Tree is empty") - return (<object>node.key, <object>node.value) - - def min_item(self): - """ Get item with min key of tree, raises ValueError if tree is empty. """ - cdef node_t *node - node = ct_min_node(self._root) - if node == NULL: # root is None - raise ValueError("Tree is empty") - return (<object>node.key, <object>node.value)
diff --git a/third_party/bintrees/bintrees/rbtree.py b/third_party/bintrees/bintrees/rbtree.py deleted file mode 100644 index dedd2bce..0000000 --- a/third_party/bintrees/bintrees/rbtree.py +++ /dev/null
@@ -1,268 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman (python version) -# Purpose: red-black tree module (Julienne Walker's none recursive algorithm) -# source: http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_rbtree.aspx -# Created: 01.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -# Conclusion of Julian Walker - -# Red black trees are interesting beasts. They're believed to be simpler than -# AVL trees (their direct competitor), and at first glance this seems to be the -# case because insertion is a breeze. However, when one begins to play with the -# deletion algorithm, red black trees become very tricky. However, the -# counterweight to this added complexity is that both insertion and deletion -# can be implemented using a single pass, top-down algorithm. Such is not the -# case with AVL trees, where only the insertion algorithm can be written top-down. -# Deletion from an AVL tree requires a bottom-up algorithm. - -# So when do you use a red black tree? That's really your decision, but I've -# found that red black trees are best suited to largely random data that has -# occasional degenerate runs, and searches have no locality of reference. This -# takes full advantage of the minimal work that red black trees perform to -# maintain balance compared to AVL trees and still allows for speedy searches. - -# Red black trees are popular, as most data structures with a whimsical name. -# For example, in Java and C++, the library map structures are typically -# implemented with a red black tree. Red black trees are also comparable in -# speed to AVL trees. While the balance is not quite as good, the work it takes -# to maintain balance is usually better in a red black tree. There are a few -# misconceptions floating around, but for the most part the hype about red black -# trees is accurate. - -from __future__ import absolute_import - -from .treemixin import TreeMixin - -__all__ = ['RBTree'] - - -class Node(object): - """ Internal object, represents a treenode """ - __slots__ = ['key', 'value', 'red', 'left', 'right'] - - def __init__(self, key=None, value=None): - self.key = key - self.value = value - self.red = True - self.left = None - self.right = None - - def free(self): - self.left = None - self.right = None - self.key = None - self.value = None - - def __getitem__(self, key): - """ x.__getitem__(key) <==> x[key], where key is 0 (left) or 1 (right) """ - return self.left if key == 0 else self.right - - def __setitem__(self, key, value): - """ x.__setitem__(key, value) <==> x[key]=value, where key is 0 (left) or 1 (right) """ - if key == 0: - self.left = value - else: - self.right = value - - -def is_red(node): - if (node is not None) and node.red: - return True - else: - return False - - -def jsw_single(root, direction): - other_side = 1 - direction - save = root[other_side] - root[other_side] = save[direction] - save[direction] = root - root.red = True - save.red = False - return save - - -def jsw_double(root, direction): - other_side = 1 - direction - root[other_side] = jsw_single(root[other_side], other_side) - return jsw_single(root, direction) - - -class RBTree(TreeMixin): - """ - RBTree implements a balanced binary tree with a dict-like interface. - - see: http://en.wikipedia.org/wiki/Red_black_tree - - A red-black tree is a type of self-balancing binary search tree, a data - structure used in computing science, typically used to implement associative - arrays. The original structure was invented in 1972 by Rudolf Bayer, who - called them "symmetric binary B-trees", but acquired its modern name in a - paper in 1978 by Leonidas J. Guibas and Robert Sedgewick. It is complex, - but has good worst-case running time for its operations and is efficient in - practice: it can search, insert, and delete in O(log n) time, where n is - total number of elements in the tree. Put very simply, a red-black tree is a - binary search tree which inserts and removes intelligently, to ensure the - tree is reasonably balanced. - - RBTree() -> new empty tree. - RBTree(mapping) -> new tree initialized from a mapping - RBTree(seq) -> new tree initialized from seq [(k1, v1), (k2, v2), ... (kn, vn)] - - see also TreeMixin() class. - - """ - def __init__(self, items=None): - """ x.__init__(...) initializes x; see x.__class__.__doc__ for signature """ - self._root = None - self._count = 0 - if items is not None: - self.update(items) - - def clear(self): - """ T.clear() -> None. Remove all items from T. """ - def _clear(node): - if node is not None: - _clear(node.left) - _clear(node.right) - node.free() - _clear(self._root) - self._count = 0 - self._root = None - - @property - def count(self): - """ count of items """ - return self._count - - @property - def root(self): - """ root node of T """ - return self._root - - def _new_node(self, key, value): - """ Create a new treenode """ - self._count += 1 - return Node(key, value) - - def insert(self, key, value): - """ T.insert(key, value) <==> T[key] = value, insert key, value into Tree """ - if self._root is None: # Empty tree case - self._root = self._new_node(key, value) - self._root.red = False # make root black - return - - head = Node() # False tree root - grand_parent = None - grand_grand_parent = head - parent = None # parent - direction = 0 - last = 0 - - # Set up helpers - grand_grand_parent.right = self._root - node = grand_grand_parent.right - # Search down the tree - while True: - if node is None: # Insert new node at the bottom - node = self._new_node(key, value) - parent[direction] = node - elif is_red(node.left) and is_red(node.right): # Color flip - node.red = True - node.left.red = False - node.right.red = False - - # Fix red violation - if is_red(node) and is_red(parent): - direction2 = 1 if grand_grand_parent.right is grand_parent else 0 - if node is parent[last]: - grand_grand_parent[direction2] = jsw_single(grand_parent, 1 - last) - else: - grand_grand_parent[direction2] = jsw_double(grand_parent, 1 - last) - - # Stop if found - if key == node.key: - node.value = value # set new value for key - break - - last = direction - direction = 0 if key < node.key else 1 - # Update helpers - if grand_parent is not None: - grand_grand_parent = grand_parent - grand_parent = parent - parent = node - node = node[direction] - - self._root = head.right # Update root - self._root.red = False # make root black - - def remove(self, key): - """ T.remove(key) <==> del T[key], remove item <key> from tree """ - if self._root is None: - raise KeyError(str(key)) - head = Node() # False tree root - node = head - node.right = self._root - parent = None - grand_parent = None - found = None # Found item - direction = 1 - - # Search and push a red down - while node[direction] is not None: - last = direction - - # Update helpers - grand_parent = parent - parent = node - node = node[direction] - - direction = 1 if key > node.key else 0 - - # Save found node - if key == node.key: - found = node - - # Push the red node down - if not is_red(node) and not is_red(node[direction]): - if is_red(node[1 - direction]): - parent[last] = jsw_single(node, direction) - parent = parent[last] - elif not is_red(node[1 - direction]): - sibling = parent[1 - last] - if sibling is not None: - if (not is_red(sibling[1 - last])) and (not is_red(sibling[last])): - # Color flip - parent.red = False - sibling.red = True - node.red = True - else: - direction2 = 1 if grand_parent.right is parent else 0 - if is_red(sibling[last]): - grand_parent[direction2] = jsw_double(parent, last) - elif is_red(sibling[1-last]): - grand_parent[direction2] = jsw_single(parent, last) - # Ensure correct coloring - grand_parent[direction2].red = True - node.red = True - grand_parent[direction2].left.red = False - grand_parent[direction2].right.red = False - - # Replace and remove if found - if found is not None: - found.key = node.key - found.value = node.value - parent[int(parent.right is node)] = node[int(node.left is None)] - node.free() - self._count -= 1 - - # Update root and make it black - self._root = head.right - if self._root is not None: - self._root.red = False - if not found: - raise KeyError(str(key)) \ No newline at end of file
diff --git a/third_party/bintrees/bintrees/stack.c b/third_party/bintrees/bintrees/stack.c deleted file mode 100644 index cb308f8..0000000 --- a/third_party/bintrees/bintrees/stack.c +++ /dev/null
@@ -1,58 +0,0 @@ -/* - * stack.c - * - * Author: mozman - * Copyright (c) 2010-2013 by Manfred Moitzi - * License: MIT-License - */ - -#include "ctrees.h" -#include "stack.h" - -extern node_stack_t * -stack_init(int size) -{ - node_stack_t *stack; - - stack = PyMem_Malloc(sizeof(node_stack_t)); - stack->stack = PyMem_Malloc(sizeof(node_t *) * size); - stack->size = size; - stack->stackptr = 0; - return stack; -} - -extern void -stack_delete(node_stack_t *stack) -{ - PyMem_Free(stack->stack); - PyMem_Free(stack); -} - -extern void -stack_push(node_stack_t *stack, node_t *node) -{ - stack->stack[stack->stackptr++] = node; - if (stack->stackptr >= stack->size) { - stack->size *= 2; - stack->stack = PyMem_Realloc(stack->stack, - sizeof(node_t *) * stack->size); - } -} - -extern node_t * -stack_pop(node_stack_t *stack) -{ - return (stack->stackptr > 0) ? stack->stack[--stack->stackptr] : NULL; -} - -extern int -stack_is_empty(node_stack_t *stack) -{ - return (stack->stackptr == 0); -} - -extern void -stack_reset(node_stack_t *stack) -{ - stack->stackptr = 0; -}
diff --git a/third_party/bintrees/bintrees/stack.h b/third_party/bintrees/bintrees/stack.h deleted file mode 100644 index 138f5ed..0000000 --- a/third_party/bintrees/bintrees/stack.h +++ /dev/null
@@ -1,28 +0,0 @@ -/* - * stack.h - * - * Author: mozman - * Copyright (c) 2010-2013 by Manfred Moitzi - * License: MIT-License - */ - -#ifndef STACK_H_ -#define STACK_H_ - -#include "ctrees.h" - -typedef struct node_stack node_stack_t; -struct node_stack { - int stackptr; - int size; - node_t **stack; -}; - -node_stack_t *stack_init(int size); -void stack_delete(node_stack_t *stack); -void stack_push(node_stack_t *stack, node_t *node); -node_t *stack_pop(node_stack_t *stack); -int stack_is_empty(node_stack_t *stack); -void stack_reset(node_stack_t *stack); - -#endif /* STACK_H_ */
diff --git a/third_party/bintrees/bintrees/stack.pxd b/third_party/bintrees/bintrees/stack.pxd deleted file mode 100644 index 7b4efd7..0000000 --- a/third_party/bintrees/bintrees/stack.pxd +++ /dev/null
@@ -1,18 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Created: 08.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT-License - -from ctrees cimport node_t - -cdef extern from "stack.h": - ctypedef struct node_stack_t: - pass - node_stack_t *stack_init(int size) - void stack_delete(node_stack_t *stack) - void stack_push(node_stack_t *stack, node_t *node) - node_t *stack_pop(node_stack_t *stack) - int stack_is_empty(node_stack_t *stack) - void stack_reset(node_stack_t *stack)
diff --git a/third_party/bintrees/bintrees/treemixin.py b/third_party/bintrees/bintrees/treemixin.py deleted file mode 100644 index 805ad95b..0000000 --- a/third_party/bintrees/bintrees/treemixin.py +++ /dev/null
@@ -1,642 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: Mozman -# Purpose: treemixin provides top level functions for binary trees -# Created: 03.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -from __future__ import absolute_import - -from .walker import Walker -from .treeslice import TreeSlice - -class TreeMixin(object): - """ - Abstract-Base-Class for the pure Python Trees: BinaryTree, AVLTree and RBTree - Mixin-Class for the Cython based Trees: FastBinaryTree, FastAVLTree, FastRBTree - - The TreeMixin Class - =================== - - T has to implement following properties - --------------------------------------- - - count -- get node count - - T has to implement following methods - ------------------------------------ - - get_walker(...) - get a tree walker object, provides methods to traverse the tree see walker.py - - insert(...) - insert(key, value) <==> T[key] = value, insert key into T - - remove(...) - remove(key) <==> del T[key], remove key from T - - clear(...) - T.clear() -> None. Remove all items from T. - - Methods defined here - -------------------- - - * __contains__(k) -> True if T has a key k, else False, O(log(n)) - * __delitem__(y) <==> del T[y], del T[s:e], O(log(n)) - * __getitem__(y) <==> T[y], T[s:e], O(log(n)) - * __iter__() <==> iter(T) - * __len__() <==> len(T), O(1) - * __max__() <==> max(T), get max item (k,v) of T, O(log(n)) - * __min__() <==> min(T), get min item (k,v) of T, O(log(n)) - * __and__(other) <==> T & other, intersection - * __or__(other) <==> T | other, union - * __sub__(other) <==> T - other, difference - * __xor__(other) <==> T ^ other, symmetric_difference - * __repr__() <==> repr(T) - * __setitem__(k, v) <==> T[k] = v, O(log(n)) - * clear() -> None, Remove all items from T, , O(n) - * copy() -> a shallow copy of T, O(n*log(n)) - * discard(k) -> None, remove k from T, if k is present, O(log(n)) - * get(k[,d]) -> T[k] if k in T, else d, O(log(n)) - * is_empty() -> True if len(T) == 0, O(1) - * items([reverse]) -> generator for (k, v) items of T, O(n) - * keys([reverse]) -> generator for keys of T, O(n) - * values([reverse]) -> generator for values of T, O(n) - * pop(k[,d]) -> v, remove specified key and return the corresponding value, O(log(n)) - * popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple, O(log(n)) - * setdefault(k[,d]) -> T.get(k, d), also set T[k]=d if k not in T, O(log(n)) - * update(E) -> None. Update T from dict/iterable E, O(E*log(n)) - * foreach(f, [order]) -> visit all nodes of tree and call f(k, v) for each node, O(n) - - slicing by keys - - * itemslice(s, e) -> generator for (k, v) items of T for s <= key < e, O(n) - * keyslice(s, e) -> generator for keys of T for s <= key < e, O(n) - * valueslice(s, e) -> generator for values of T for s <= key < e, O(n) - * T[s:e] -> TreeSlice object, with keys in range s <= key < e, O(n) - * del T[s:e] -> remove items by key slicing, for s <= key < e, O(n) - - if 's' is None or T[:e] TreeSlice/iterator starts with value of min_key() - if 'e' is None or T[s:] TreeSlice/iterator ends with value of max_key() - T[:] is a TreeSlice which represents the whole tree. - - TreeSlice is a tree wrapper with range check, and contains no references - to objects, deleting objects in the associated tree also deletes the object - in the TreeSlice. - - * TreeSlice[k] -> get value for key k, raises KeyError if k not exists in range s:e - * TreeSlice[s1:e1] -> TreeSlice object, with keys in range s1 <= key < e1 - - * new lower bound is max(s, s1) - * new upper bound is min(e, e1) - - TreeSlice methods: - - * items() -> generator for (k, v) items of T, O(n) - * keys() -> generator for keys of T, O(n) - * values() -> generator for values of T, O(n) - * __iter__ <==> keys() - * __repr__ <==> repr(T) - * __contains__(key)-> True if TreeSlice has a key k, else False, O(log(n)) - - prev/succ operations - - * prev_item(key) -> get (k, v) pair, where k is predecessor to key, O(log(n)) - * prev_key(key) -> k, get the predecessor of key, O(log(n)) - * succ_item(key) -> get (k,v) pair as a 2-tuple, where k is successor to key, O(log(n)) - * succ_key(key) -> k, get the successor of key, O(log(n)) - * floor_item(key) -> get (k, v) pair, where k is the greatest key less than or equal to key, O(log(n)) - * floor_key(key) -> k, get the greatest key less than or equal to key, O(log(n)) - * ceiling_item(key) -> get (k, v) pair, where k is the smallest key greater than or equal to key, O(log(n)) - * ceiling_key(key) -> k, get the smallest key greater than or equal to key, O(log(n)) - - Heap methods - - * max_item() -> get largest (key, value) pair of T, O(log(n)) - * max_key() -> get largest key of T, O(log(n)) - * min_item() -> get smallest (key, value) pair of T, O(log(n)) - * min_key() -> get smallest key of T, O(log(n)) - * pop_min() -> (k, v), remove item with minimum key, O(log(n)) - * pop_max() -> (k, v), remove item with maximum key, O(log(n)) - * nlargest(i[,pop]) -> get list of i largest items (k, v), O(i*log(n)) - * nsmallest(i[,pop]) -> get list of i smallest items (k, v), O(i*log(n)) - - Set methods (using frozenset) - - * intersection(t1, t2, ...) -> Tree with keys *common* to all trees - * union(t1, t2, ...) -> Tree with keys from *either* trees - * difference(t1, t2, ...) -> Tree with keys in T but not any of t1, t2, ... - * symmetric_difference(t1) -> Tree with keys in either T and t1 but not both - * issubset(S) -> True if every element in T is in S - * issuperset(S) -> True if every element in S is in T - * isdisjoint(S) -> True if T has a null intersection with S - - Classmethods - - * fromkeys(S[,v]) -> New tree with keys from S and values equal to v. - - """ - def get_walker(self): - return Walker(self) - - def __repr__(self): - """ x.__repr__(...) <==> repr(x) """ - tpl = "%s({%s})" % (self.__class__.__name__, '%s') - return tpl % ", ".join( ("%r: %r" % item for item in self.items()) ) - - def copy(self): - """ T.copy() -> get a shallow copy of T. """ - tree = self.__class__() - self.foreach(tree.insert, order=-1) - return tree - __copy__ = copy - - def __contains__(self, key): - """ k in T -> True if T has a key k, else False """ - try: - self.get_value(key) - return True - except KeyError: - return False - - def __len__(self): - """ x.__len__() <==> len(x) """ - return self.count - - def __min__(self): - """ x.__min__() <==> min(x) """ - return self.min_item() - - def __max__(self): - """ x.__max__() <==> max(x) """ - return self.max_item() - - def __and__(self, other): - """ x.__and__(other) <==> self & other """ - return self.intersection(other) - - def __or__(self, other): - """ x.__or__(other) <==> self | other """ - return self.union(other) - - def __sub__(self, other): - """ x.__sub__(other) <==> self - other """ - return self.difference(other) - - def __xor__(self, other): - """ x.__xor__(other) <==> self ^ other """ - return self.symmetric_difference(other) - - def discard(self, key): - """ x.discard(k) -> None, remove k from T, if k is present """ - try: - self.remove(key) - except KeyError: - pass - - def __del__(self): - self.clear() - - def is_empty(self): - """ x.is_empty() -> False if T contains any items else True""" - return self.count == 0 - - def keys(self, reverse=False): - """ T.iterkeys([reverse]) -> an iterator over the keys of T, in ascending - order if reverse is True, iterate in descending order, reverse defaults - to False - """ - return ( item[0] for item in self.items(reverse) ) - __iter__ = keys - - def __reversed__(self): - return self.keys(reverse=True) - - def values(self, reverse=False): - """ T.values([reverse]) -> an iterator over the values of T, in ascending order - if reverse is True, iterate in descending order, reverse defaults to False - """ - return ( item[1] for item in self.items(reverse) ) - - def items(self, reverse=False): - """ T.items([reverse]) -> an iterator over the (key, value) items of T, - in ascending order if reverse is True, iterate in descending order, - reverse defaults to False - """ - if self.is_empty(): - return [] - - def default_iterator(node): - direction = 1 if reverse else 0 - other = 1 - direction - go_down = True - while True: - if node.has_child(direction) and go_down: - node.push() - node.down(direction) - else: - yield node.item - if node.has_child(other): - node.down(other) - go_down = True - else: - if node.stack_is_empty(): - return # all done - node.pop() - go_down = False - - treewalker = self.get_walker() - try: # specialized iterators - if reverse: - return treewalker.iter_items_backward() - else: - return treewalker.iter_items_forward() - except AttributeError: - return default_iterator(treewalker) - - def __getitem__(self, key): - """ x.__getitem__(y) <==> x[y] """ - if isinstance(key, slice): - return TreeSlice(self, key.start, key.stop) - else: - return self.get_value(key) - - def __setitem__(self, key, value): - """ x.__setitem__(i, y) <==> x[i]=y """ - if isinstance(key, slice): - raise ValueError('setslice is not supported') - self.insert(key, value) - - def __delitem__(self, key): - """ x.__delitem__(y) <==> del x[y] """ - if isinstance(key, slice): - self.delitems(self.keyslice(key.start, key.stop)) - else: - self.remove(key) - - def delitems(self, keys): - """ T.delitems(keys) -> remove all items by keys - """ - # convert generator to a set, because the content of the - # tree will be modified! - for key in frozenset(keys): - self.remove(key) - - def keyslice(self, startkey, endkey): - """ T.keyslice(startkey, endkey) -> key iterator: - startkey <= key < endkey. - """ - return ( item[0] for item in self.itemslice(startkey, endkey) ) - - def itemslice(self, startkey, endkey): - """ T.itemslice(s, e) -> item iterator: s <= key < e. - - if s is None: start with min element -> T[:e] - if e is None: end with max element -> T[s:] - T[:] -> all items - - """ - if self.is_empty(): - return - - if startkey is None: - # no lower bound - can_go_left = lambda: node.has_left() and visit_left - else: - # don't visit subtrees without keys in search range - can_go_left = lambda: node.key > startkey and node.has_left() and visit_left - - if endkey is None: - # no upper bound - can_go_right = lambda: node.has_right() - else: - # don't visit subtrees without keys in search range - can_go_right = lambda: node.key < endkey and node.has_right() - - if (startkey, endkey) == (None, None): - key_in_range = lambda: True - elif startkey is None: - key_in_range = lambda: node.key < endkey - elif endkey is None: - key_in_range = lambda: node.key >= startkey - else: - key_in_range = lambda: startkey <= node.key < endkey - - node = self.get_walker() - visit_left = True - while True: - if can_go_left(): - node.push() - node.go_left() - else: - if key_in_range(): - yield node.item - if can_go_right(): - node.go_right() - visit_left = True - else: - if node.stack_is_empty(): - return - node.pop() - # left side is already done - visit_left = False - - def valueslice(self, startkey, endkey): - """ T.valueslice(startkey, endkey) -> value iterator: - startkey <= key < endkey. - """ - return ( item[1] for item in self.itemslice(startkey, endkey) ) - - def get_value(self, key): - node = self.root - while node is not None: - if key == node.key: - return node.value - elif key < node.key: - node = node.left - else: - node = node.right - raise KeyError(str(key)) - - def __getstate__(self): - return dict(self.items()) - - def __setstate__(self, state): - # note for myself: this is called like __init__, so don't use clear() - # to remove existing data! - self._root = None - self._count = 0 - self.update(state) - - def setdefault(self, key, default=None): - """ T.setdefault(k[,d]) -> T.get(k,d), also set T[k]=d if k not in T """ - try: - return self.get_value(key) - except KeyError: - self.insert(key, default) - return default - - def update(self, *args): - """ T.update(E) -> None. Update T from E : for (k, v) in E: T[k] = v """ - for items in args: - try: - generator = items.items() - except AttributeError: - generator = iter(items) - - for key, value in generator: - self.insert(key, value) - - @classmethod - def fromkeys(cls, iterable, value=None): - """ T.fromkeys(S[,v]) -> New tree with keys from S and values equal to v. - - v defaults to None. - """ - tree = cls() - for key in iterable: - tree.insert(key, value) - return tree - - def get(self, key, default=None): - """ T.get(k[,d]) -> T[k] if k in T, else d. d defaults to None. """ - try: - return self.get_value(key) - except KeyError: - return default - - def pop(self, key, *args): - """ T.pop(k[,d]) -> v, remove specified key and return the corresponding value - If key is not found, d is returned if given, otherwise KeyError is raised - """ - if len(args) > 1: - raise TypeError("pop expected at most 2 arguments, got %d" % (1 + len(args))) - try: - value = self.get_value(key) - self.remove(key) - return value - except KeyError: - if len(args) == 0: - raise - else: - return args[0] - - def popitem(self): - """ T.popitem() -> (k, v), remove and return some (key, value) pair as a - 2-tuple; but raise KeyError if T is empty - """ - if self.is_empty(): - raise KeyError("popitem(): tree is empty") - walker = self.get_walker() - walker.goto_leaf() - result = walker.item - self.remove(walker.key) - return result - - def foreach(self, func, order=0): - """ Visit all tree nodes and process key, value. - - parm func: function(key, value) - param int order: inorder = 0, preorder = -1, postorder = +1 - - """ - def _traverse(): - if order == -1: - func(node.key, node.value) - if node.has_left(): - node.push() - node.go_left() - _traverse() - node.pop() - if order == 0: - func(node.key, node.value) - if node.has_right(): - node.push() - node.go_right() - _traverse() - node.pop() - if order == +1: - func(node.key, node.value) - - node = self.get_walker() - _traverse() - - def min_item(self): - """ Get item with min key of tree, raises ValueError if tree is empty. """ - if self.count == 0: - raise ValueError("Tree is empty") - node = self._root - while node.left is not None: - node = node.left - return (node.key, node.value) - - def pop_min(self): - """ T.pop_min() -> (k, v), remove item with minimum key, raise ValueError - if T is empty. - """ - item = self.min_item() - self.remove(item[0]) - return item - - def min_key(self): - """ Get min key of tree, raises ValueError if tree is empty. """ - key, value = self.min_item() - return key - - def prev_item(self, key): - """ Get predecessor (k,v) pair of key, raises KeyError if key is min key - or key does not exist. - """ - if self.count == 0: - raise KeyError("Tree is empty") - walker = self.get_walker() - return walker.prev_item(key) - - def succ_item(self, key): - """ Get successor (k,v) pair of key, raises KeyError if key is max key - or key does not exist. - """ - if self.count == 0: - raise KeyError("Tree is empty") - walker = self.get_walker() - return walker.succ_item(key) - - def prev_key(self, key): - """ Get predecessor to key, raises KeyError if key is min key - or key does not exist. - """ - key, value = self.prev_item(key) - return key - - def succ_key(self, key): - """ Get successor to key, raises KeyError if key is max key - or key does not exist. - """ - key, value = self.succ_item(key) - return key - - def floor_item(self, key): - """ Get the element (k,v) pair associated with the greatest key less - than or equal to the given key, raises KeyError if there is no such key. - """ - if self.count == 0: - raise KeyError("Tree is empty") - walker = self.get_walker() - return walker.floor_item(key) - - def floor_key(self, key): - """ Get the greatest key less than or equal to the given key, raises - KeyError if there is no such key. - """ - key, value = self.floor_item(key) - return key - - def ceiling_item(self, key): - """ Get the element (k,v) pair associated with the smallest key greater - than or equal to the given key, raises KeyError if there is no such key. - """ - if self.count == 0: - raise KeyError("Tree is empty") - walker = self.get_walker() - return walker.ceiling_item(key) - - def ceiling_key(self, key): - """ Get the smallest key greater than or equal to the given key, raises - KeyError if there is no such key. - """ - key, value = self.ceiling_item(key) - return key - - def max_item(self): - """ Get item with max key of tree, raises ValueError if tree is empty. """ - if self.count == 0: - raise ValueError("Tree is empty") - node = self._root - while node.right is not None: - node = node.right - return (node.key, node.value) - - def pop_max(self): - """ T.pop_max() -> (k, v), remove item with maximum key, raise ValueError - if T is empty. - """ - item = self.max_item() - self.remove(item[0]) - return item - - def max_key(self): - """ Get max key of tree, raises ValueError if tree is empty. """ - key, value = self.max_item() - return key - - def nsmallest(self, n, pop=False): - """ T.nsmallest(n) -> get list of n smallest items (k, v). - If pop is True, remove items from T. - """ - if pop: - return [self.pop_min() for _ in range(min(len(self), n))] - else: - items = self.items() - return [ next(items) for _ in range(min(len(self), n)) ] - - def nlargest(self, n, pop=False): - """ T.nlargest(n) -> get list of n largest items (k, v). - If pop is True remove items from T. - """ - if pop: - return [self.pop_max() for _ in range(min(len(self), n))] - else: - items = self.items(reverse=True) - return [ next(items) for _ in range(min(len(self), n)) ] - - def intersection(self, *trees): - """ x.intersection(t1, t2, ...) -> Tree, with keys *common* to all trees - """ - thiskeys = frozenset(self.keys()) - sets = _build_sets(trees) - rkeys = thiskeys.intersection(*sets) - return self.__class__( ((key, self.get(key)) for key in rkeys) ) - - def union(self, *trees): - """ x.union(t1, t2, ...) -> Tree with keys from *either* trees - """ - thiskeys = frozenset(self.keys()) - rkeys = thiskeys.union(*_build_sets(trees)) - return self.__class__( ((key, self.get(key)) for key in rkeys) ) - - def difference(self, *trees): - """ x.difference(t1, t2, ...) -> Tree with keys in T but not any of t1, - t2, ... - """ - thiskeys = frozenset(self.keys()) - rkeys = thiskeys.difference(*_build_sets(trees)) - return self.__class__( ((key, self.get(key)) for key in rkeys) ) - - def symmetric_difference(self, tree): - """ x.symmetric_difference(t1) -> Tree with keys in either T and t1 but - not both - """ - thiskeys = frozenset(self.keys()) - rkeys = thiskeys.symmetric_difference(frozenset(tree.keys())) - return self.__class__( ((key, self.get(key)) for key in rkeys) ) - - def issubset(self, tree): - """ x.issubset(tree) -> True if every element in x is in tree """ - thiskeys = frozenset(self.keys()) - return thiskeys.issubset(frozenset(tree.keys())) - - def issuperset(self, tree): - """ x.issubset(tree) -> True if every element in tree is in x """ - thiskeys = frozenset(self.keys()) - return thiskeys.issuperset(frozenset(tree.keys())) - - def isdisjoint(self, tree): - """ x.isdisjoint(S) -> True if x has a null intersection with tree """ - thiskeys = frozenset(self.keys()) - return thiskeys.isdisjoint(frozenset(tree.keys())) - - -def _build_sets(trees): - return [ frozenset(tree.keys()) for tree in trees ] -
diff --git a/third_party/bintrees/bintrees/treeslice.py b/third_party/bintrees/bintrees/treeslice.py deleted file mode 100644 index 80fb680..0000000 --- a/third_party/bintrees/bintrees/treeslice.py +++ /dev/null
@@ -1,70 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -- <mozman@gmx.at> -# Purpose: TreeSlice -# Created: 11.04.2011 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - - -class TreeSlice(object): - __slots__ = ['_tree', '_start', '_stop'] - - def __init__(self, tree, start, stop): - self._tree = tree - self._start = start - self._stop = stop - - def __repr__(self): - tpl = "%s({%s})" % (self._tree.__class__.__name__, '%s') - return tpl % ", ".join( ("%r: %r" % item for item in self.items()) ) - - def __contains__(self, key): - if self._inrange(key): - return key in self._tree - else: - return False - - def _inrange(self, key): - if self._start is not None and key < self._start: - return False - if self._stop is not None and key >= self._stop: - return False - return True - - def __getitem__(self, key): - if isinstance(key, slice): - return self._subslice(key.start, key.stop) - if self._inrange(key): - return self._tree[key] - else: - raise KeyError(key) - - def _subslice(self, start, stop): - def newstart(): - if start is None: - return self._start - elif self._start is None: - return start - else: - return max(start, self._start) - - def newstop(): - if stop is None: - return self._stop - elif self._stop is None: - return stop - else: - return min(stop, self._stop) - - return TreeSlice(self._tree, newstart(), newstop()) - - def keys(self): - return self._tree.keyslice(self._start, self._stop) - __iter__ = keys - - def values(self): - return self._tree.valueslice(self._start, self._stop) - - def items(self): - return self._tree.itemslice(self._start, self._stop)
diff --git a/third_party/bintrees/bintrees/walker.py b/third_party/bintrees/bintrees/walker.py deleted file mode 100644 index 3041d3db..0000000 --- a/third_party/bintrees/bintrees/walker.py +++ /dev/null
@@ -1,220 +0,0 @@ -#!/usr/bin/env python -#coding:utf-8 -# Author: mozman -# Purpose: tree walker -# Created: 07.05.2010 -# Copyright (c) 2010-2013 by Manfred Moitzi -# License: MIT License - -from operator import attrgetter, lt, gt - - -class Walker(object): - __slots__ = ['_node', '_stack', '_tree'] - - def __init__(self, tree): - self._tree = tree - self._node = tree.root - self._stack = [] - - def reset(self): - self._stack = [] - self._node = self._tree.root - - @property - def key(self): - return self._node.key - - @property - def value(self): - return self._node.value - - @property - def item(self): - return (self._node.key, self._node.value) - - @property - def is_valid(self): - return self._node is not None - - def goto(self, key): - self._node = self._tree.root - while self._node is not None: - if key == self._node.key: - return True - elif key < self._node.key: - self.go_left() - else: - self.go_right() - return False - - def push(self): - self._stack.append(self._node) - - def pop(self): - self._node = self._stack.pop() - - def stack_is_empty(self): - return len(self._stack) == 0 - - def goto_leaf(self): - """ get a leaf node """ - while self._node is not None: - if self.has_left(): - self.go_left() - elif self.has_right(): - self.go_right() - else: - return - - def has_child(self, direction): - if direction == 0: - return self._node.left is not None - else: - return self._node.right is not None - - def down(self, direction): - if direction == 0: - self._node = self._node.left - else: - self._node = self._node.right - - def go_left(self): - self._node = self._node.left - - def go_right(self): - self._node = self._node.right - - def has_left(self): - return self._node.left is not None - - def has_right(self): - return self._node.right is not None - - def _next_item(self, key, left, right, less_than): - node = self._tree.root - succ = None - while node is not None: - if key == node.key: - break - elif less_than(key, node.key): - if (succ is None) or less_than(node.key, succ.key): - succ = node - node = left(node) - else: - node = right(node) - - if node is None: # stay at dead end - raise KeyError(str(key)) - # found node of key - if right(node) is not None: - # find smallest node of right subtree - node = right(node) - while left(node) is not None: - node = left(node) - if succ is None: - succ = node - elif less_than(node.key, succ.key): - succ = node - elif succ is None: # given key is biggest in tree - raise KeyError(str(key)) - return (succ.key, succ.value) - - def succ_item(self, key): - """ Get successor (k,v) pair of key, raises KeyError if key is max key - or key does not exist. - """ - return self._next_item( - key, - left=attrgetter("left"), - right=attrgetter("right"), - less_than=lt, - ) - - def prev_item(self, key): - """ Get predecessor (k,v) pair of key, raises KeyError if key is min key - or key does not exist. - """ - return self._next_item( - key, - left=attrgetter("right"), - right=attrgetter("left"), - less_than=gt, - ) - - def _iteritems(self, left=attrgetter("left"), right=attrgetter("right")): - """ optimized forward iterator (reduced method calls) """ - if self._tree.is_empty(): - return - node = self._tree.root - stack = self._stack - go_left = True - while True: - if left(node) is not None and go_left: - stack.append(node) - node = left(node) - else: - yield (node.key, node.value) - if right(node) is not None: - node = right(node) - go_left = True - else: - if len(stack) == 0: - return # all done - node = stack.pop() - go_left = False - - def iter_items_forward(self): - for item in self._iteritems( - left=attrgetter("left"), - right=attrgetter("right"), - ): - yield item - - def iter_items_backward(self): - for item in self._iteritems( - left=attrgetter("right"), - right=attrgetter("left"), - ): - yield item - - def floor_item(self, key): - """ Get the element (k,v) pair associated with the greatest key less - than or equal to the given key, raises KeyError if there is no such key. - """ - node = self._tree.root - prev = None - while node is not None: - if key == node.key: - return node.key, node.value - elif key < node.key: - node = node.left - else: - if (prev is None) or (node.key > prev.key): - prev = node - node = node.right - # node must be None here - if prev: - return prev.key, prev.value - raise KeyError(str(key)) - - def ceiling_item(self, key): - """ Get the element (k,v) pair associated with the smallest key greater - than or equal to the given key, raises KeyError if there is no such key. - """ - node = self._tree.root - succ = None - while node is not None: - if key == node.key: - return node.key, node.value - elif key > node.key: - node = node.right - else: - if (succ is None) or (node.key < succ.key): - succ = node - node = node.left - # node must be None here - if succ: - return succ.key, succ.value - raise KeyError(str(key)) -
diff --git a/tools/checkperms/checkperms.py b/tools/checkperms/checkperms.py index 8e75974..9960558 100755 --- a/tools/checkperms/checkperms.py +++ b/tools/checkperms/checkperms.py
@@ -182,7 +182,6 @@ '__init__.py', 'out/', # TODO(maruel): Fix these. - 'third_party/bintrees/', 'third_party/devscripts/licensecheck.pl.vanilla', 'third_party/hyphen/', 'third_party/lcov-1.9/contrib/galaxy/conglomerate_functions.pl',
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 7c1c2b2..c57beff 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml
@@ -89698,6 +89698,7 @@ <int value="1783" label="HTMLTableCellElementColspan"/> <int value="1784" label="HTMLTableCellElementColspanGreaterThan1000"/> <int value="1785" label="HTMLTableCellElementColspanGreaterThan8190"/> + <int value="1786" label="SelectionAddRangeIntersect"/> </enum> <enum name="FetchRequestMode" type="int">
diff --git a/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java b/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java index 82d09ea..9a9d89b 100644 --- a/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java +++ b/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java
@@ -107,6 +107,7 @@ /** * @return container view that the anchor views are added to. May be null. */ + @CalledByNative public abstract ViewGroup getContainerView(); /**
diff --git a/ui/android/view_android.cc b/ui/android/view_android.cc index b2194879..6c55a7bf 100644 --- a/ui/android/view_android.cc +++ b/ui/android/view_android.cc
@@ -133,6 +133,15 @@ bounds.height(), scale, left_margin, top_margin); } +ScopedJavaLocalRef<jobject> ViewAndroid::GetContainerView() { + ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); + if (delegate.is_null()) + return nullptr; + + JNIEnv* env = base::android::AttachCurrentThread(); + return Java_ViewAndroidDelegate_getContainerView(env, delegate); +} + void ViewAndroid::RemoveChild(ViewAndroid* child) { DCHECK(child); DCHECK_EQ(child->parent_, this);
diff --git a/ui/android/view_android.h b/ui/android/view_android.h index db49468b8..68adf34 100644 --- a/ui/android/view_android.h +++ b/ui/android/view_android.h
@@ -94,6 +94,9 @@ void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, const gfx::RectF& bounds); + // This may return null. + base::android::ScopedJavaLocalRef<jobject> GetContainerView(); + protected: ViewAndroid* parent_;