input stringlengths 10 828 | output stringlengths 5 107 |
|---|---|
public boolean is empty return n 0 | determine if binary heap is empty |
public boolean sort comparable e ar int left int right if right left return false form a heap this could be done in place but this is simpler coding binary heap e heap new binary heap e right left 1 int i left while i right heap insert i ar i i i left while heap is empty ar i heap smallest return true | sort using heapsort method |
public boolean sort e ar int left int right comparator e comparator if right left return false form a heap this could be done in place but this is simpler coding external binary heap e heap new external binary heap e right left 1 comparator object sorted new object right left 1 int i left while i right heap insert ar i i i left while heap is empty sorted i heap smallest copy back in system arraycopy sorted 0 ar left sorted length return true | sort using heapsort method with external comparator |
public void add count count | increase number of trials with this time |
public string to string return time t count | reasonable to string method |
public int compare to hist pair hp if time hp time return 0 if time hp time return 1 return 1 | compare by time only |
public v minimum balanced binary node k v p root if p null return null while p left null p p left v old value p value delete entry p return old value | removes and returns minimum value in tree |
public string draw igraph entity n return style filled fillcolor gray50 label n node label | half grayscale colored nodes |
public string draw igraph entity n string special font if n instanceof iselect font string font name iselect font n font name if font name null special font fontname iselect font n font name int sz iselect font n font size if sz 0 special font fontsize sz return special font label n node label | default node is drawn simply using its node label |
public string to string return dimension point | reasonable to string method |
public legend string s legend s | construct the legend contents from a string |
public string draw igraph entity n return fillcolor 8 8 8 label n node label | discarded nodes are drawn in grayscale |
public string node label return legend | return label from the legend |
public binary heap int n n 0 initially none in the heap simplify algorithm to consider position 1 as being the root elements new object n 1 for int k 0 k n 1 k elements k new element h pos new int n 1 | construct binary heap of the given size |
public int smallest id element h el smallest return el id | return the integer identifier of the smallest entry |
public void decrease key int id comparable e reduced priority int size n truncate heap temporarily and act like the binary heap up to but not including this one is all that exists cute huh n pos id 1 now we insert and the binary heap is shuffled appropriately insert id reduced priority since the new priority must be lower we can expand back and we still have a working binary heap n size | decrease the priority of the known element in the binary heap with the |
public simple string char chars this chars new char chars length for int i 0 i chars length i this chars i chars i | store copy of character array |
public simple string string s this chars s to char array | produce char array from existing java |
public string to string return new string chars | reasonable to string method |
public void ordering string ord ordering ord | ordering of children |
public void rank string r optional rank rankdir r | rank orientation of the figure |
public string node type return record | default to having nodes with complex record shapes |
public string edge type return dir none | edges should be undirected |
private void add node string builder graph igraph entity node graph append get key node label node node label | helper methods for depicting the contents of the node |
public element string name string symbol int number float mass this name symbol number mass true | constructor for a stable element |
public element string name string symbol int number float mass boolean stable this name name this symbol symbol this mass mass this number number this stable stable | constructor for a chemical element |
public board int n board new boolean n n this n n | construct the n by n board |
private boolean valid int row int col another queen in same column left diagonal or right diagonal int d 0 while d row if board row d col return false if col d board row d col d return false if col d n board row d col d return false return true ok | start with row and work upwards to see if still valid |
public boolean random next board int r int sz next valid row positions size if sz 0 return false int c int math random sz board r next valid row positions get c true return true | if no board is available then return false |
protected string get key igraph entity value for iterator string it nodes key set iterator it has next string key it next igraph entity target nodes get key if target value return key return null | helper function to reverse locate the key |
public boolean is unstable return stable | determine if this chemical element is unstable |
public string to string if stable return symbol mass int isotope mass int mass return symbol isotope mass | return string representation of element |
public boolean equals object o if o null return false if o instanceof element element other element o return other symbol equals symbol other name equals name other number number other mass mass other stable stable nope return false | determine equality based solely on the atomic symbol |
public void mark start igraph entity st start get key st | mark the start node |
public void mark goal igraph entity gl goal get key gl | mark the goal node found |
public void accept ibalanced visitor k v visitor if root null return accept null root visitor | accept a visitor for a inorder traversal |
public void visit edge igraph entity n1 igraph entity n2 string k1 get key n1 string k2 get key n2 edges append new edge pair k1 k2 | if called multiple times multiple edges result |
public void visit edge igraph entity n1 igraph entity n2 string label string k1 get key n1 string k2 get key n2 edge pair ep new edge pair k1 k2 ep label label edges append ep | assign label to the edge upon creation |
public void test zero length line sweep dba new line sweep showed a problem iline segment segments new iline segment new two dline segment 0 0 5 5 new two dline segment 2 2 2 2 hashtable ipoint list iline segment res dba intersections segments for ipoint ip res key set list iline segment ilss res get ip system out println ip for iline segment ils ilss system out println ils system out println assert equals 1 res size | zero length segments note that the intersection point will |
private string to string balanced binary node k v node if node null return string builder sb new string builder sb append to string node left sb append node to string sb append to string node right return sb append to string | return string of sub tree rooted at node |
public void test collinear line sweep dba new line sweep showed a problem iline segment segments new iline segment new two dline segment 0 0 5 5 new two dline segment 2 2 10 10 hashtable ipoint list iline segment res dba intersections segments for ipoint ip res key set list iline segment ilss res get ip system out println ip for iline segment ils ilss system out println ils system out println assert equals 2 res size | collinear points shouldnt cause problems |
public void mark edge igraph entity n1 igraph entity n2 string k1 get key n1 string k2 get key n2 node edge pair n edges head while n null edge pair ep n value if ep start key equals k1 ep end key equals k2 ep mark break n n next | mark special edges in bold |
public int dimensionality return 3 | hyperpoint inner new hyperpoint 4 7 5 different |
public string to string if root null return return to string root | return parenthetical string of tree structure using in order traversal |
public string to string return super to string low value high value | reasonable extension to to string method |
public void set up edges out new edge info 2 edges in new edge info 2 edges new array list edge info edges add edges out 0 new edge info 0 1 3 edges add edges out 1 new edge info 0 2 2 edges add new edge info 1 4 2 edges add new edge info 2 3 2 edges add new edge info 2 4 3 edges add new edge info 1 3 2 edges add edges in 0 new edge info 3 5 3 edges add edges in 1 new edge info 4 5 2 | example intended to show why traversing backedges to reduce flows works |
public void set up edges out new edge info 2 edges in new edge info 2 edges new array list edge info edges add edges out 0 new edge info 0 1 3 edges add edges out 1 new edge info 0 2 2 edges add new edge info 1 3 2 edges add new edge info 1 4 2 edges add new edge info 2 3 2 edges add new edge info 2 4 3 edges add edges out 0 new edge info 3 5 3 edges add edges out 1 new edge info 4 5 2 | figure 8 fact sheet |
public plus move | increment move selects the position to be incremented |
public boolean is valid inode state one puzzle op one puzzle state return op s one puzzle max value | moves are valid as long as state max value |
public one puzzle s 0 | initialize to empty |
public one puzzle int x s x | initialize to pre existing board state |
public string pack iterator integer it string builder sb new string builder while it has next sb append it next remove trailing comma if possible if sb length 0 sb delete char at sb length 1 return sb to string | extract all values from the iterator and pack into a comma separated string |
public inode copy return new one puzzle s | return copy of node |
public void score int score this score score | set score for this node |
public int compare to one puzzle op return s op s | needed for nodes to be placed within binary tree |
public void test hitchcock int sup new int 4 5 3 9 int dem new int 3 3 6 2 1 2 int d new int 5 3 7 3 8 5 5 6 12 5 7 11 2 8 3 4 8 2 9 6 10 5 10 9 transportation tr new transportation sup dem d ford fulkerson ff new ford fulkerson tr new shortest path array tr ff compute assert equals 17 tr get flow assert equals 93 tr get cost | show how to use max flow to solve hitchchock transportation problem |
protected void init application context throws beans exception if is cache get transformer factory | pre initialize the factory from the xml file |
public saxtransformer factory get sax transformer handler synchronized tr xo class if stf null stf saxtransformer factory transformer factory new instance stf set uriresolver this return stf | creates a new identity transformer |
public void set async boolean value this async value | sets the value of the async property |
public void comment string text throws saxexception if text null char chars text to char array get lexical handler comment chars 0 chars length | generates sax events for the given text |
protected string get page name string lookup path this url path helper get lookup path for request get request if log is debug enabled log debug looking up handler for lookup path return lookup path | look up a handler for the url path of the given request |
public boolean has next return param name matcher find | returns true if the call to next will return a token rather |
override protected void startup show new map view this | at startup create and show the main frame of the application |
private folder get folder element emp el string name get text value emp el name string selected get text value emp el selected if integer parse int selected 0 return new folder name false else return new folder name true | i take an employee element and read the values in create |
private folder get folder element emp el string name get text value emp el name folder l new folder name return l | i take an employee element and read the values in create |
private link get link element emp el string imdb emp el get attribute imdb string naam get text value emp el name string year get text value emp el year string score get text value emp el score link l new link imdb naam year score return l | i take an employee element and read the values in create |
public void started server state state set string roles log warn started the server has started publishing state and roles to the cluster if roles null set roles roles null either the roles were not provided or the roles have not changed publish the existing roles to the cluster anyway publish roles roles ref get attempt to set the new state if provided if state null set state state null either the state was not provided or the state has not changed publish the existing state to the cluster anyway publish state state ref get | this method should be called after the server has fully initialized so |
public server endpoint get server endpoint string group name return jboss server get instance get server endpoint group name | the server end point for the given group |
public server state view set state server state state throws illegal argument exception for server state view previous state view state ref get if previous state view get state state return null server state view new state view inner compare and set state previous state view state if new state view null return new state view | sets the state of the server |
public void request server state broadcast string group name if invalidation manager null publish invalidation notification invalidation manager batch invalidate create server state broadcast request group name true | requests a broadcast of the state of all servers in the cluster |
public void request node roles broadcast string group name if invalidation manager null publish invalidation notification invalidation manager batch invalidate create roles broadcast request group name true | requests a broadcast of the node roles of all servers in the cluster |
public server node config get long id throws server node config exception server node config dao server config dao persistence manager get id return new server node config impl server config dao get id server config dao get node id server config dao get description server config dao get host server config dao get port get node role ids server config dao | retrieves the server node config for the given id primary key |
public void publish state string group name publish state group name state ref get | publishes the state of this server to all listeners of the given group |
public void publish roles string group name publish roles group name roles ref get | publishes the roles of this server to all listeners of the given group |
public server state get state return get state view get state | gets the transient state of the server |
public server state view get state view return state ref get | returns the server state view which also includes the view id |
private void generate node resolver element parent extendable string node resolver id if node resolver id null node resolver id get inheritance inheritance inherited create text element parent node resolver element node resolver id to string | generate the node resolver element |
public server info get server info todo should get rid of this method iterator string it get all server endpoints key set iterator if it has next return get server info it next throw new runtime exception no server endpoints registered | returns information about the server |
private void generate default load balance policy element parent extendable string default load balance policy definition id if default load balance policy definition id null default load balance policy definition id get inheritance inheritance inherited create text element parent default load balance policy element default load balance policy definition id to string | generate the default load balance policy element |
private void generate load balance policies element parent collection factory definition load balance policy load balance policy definitions for factory definition load balance policy factory def load balance policy definitions if factory def get inheritance inheritance inherited generate load balance policy parent factory def | generate the load balance policy elements |
public object register listener string group name invalidatable listener org jboss cache invalidation invalidatable jboss listener new jboss invalidatable wrapper listener get invalidation group group name register jboss listener return jboss listener | registers a listener that will be notified when a servers state changes |
public void unregister listener string group name object listener key if listener key instanceof org jboss cache invalidation invalidatable get invalidation group group name unregister org jboss cache invalidation invalidatable listener key else throw new illegal argument exception invalid listener key | unregister the listener that was registered using the call |
private element generate meta data element parent map string extendable string meta data element meta data element create element parent metadata element for map entry string extendable string entry meta data entry set string name entry get key extendable string extendable value entry get value if extendable value get inheritance inheritance inherited continue generate meta meta data element name extendable value to string return meta data element | generates a meta data element for the given meta data map |
private element generate meta element parent string name string value element attribute element create text element parent meta element value attribute element set attribute name attribute name return attribute element | generates a meta element for the given name value pair |
public throttle get request throttle throttle request throttle throttle get if request throttle null throw new illegal state exception request throttle is not set return request throttle | returns the request throttle object |
private element generate attributes element parent map string collection string attributes element attributes element create element parent attributes element for map entry string collection string entry attributes entry set generate attributes attributes element entry get key entry get value return attributes element | generates an attributes element for the given attribute map |
public void set request throttle throttle request throttle if throttle compare and set null request throttle throw new illegal state exception request throttle is already set | sets registers the request throttle object |
private void mark as unavailable long off line until system current time millis offline period if offline start time compare and set 0 off line until if log is debug enabled log debug mark as unavailable id owner id the node has been marked as unavailable until new date off line until else if log is debug enabled log debug mark as unavailable id owner id the node is has already been marked as unavailable by another thread | marks the node as unavailable for a period of offline period milliseconds |
private void generate attributes element parent string name collection string values for string value values generate attribute parent name value | generates attribute elements for the given name and collection of values |
public boolean is request throttle set return throttle get null | indicates whether the request throttle object was set |
private element generate attribute element parent string name string value element attribute element create text element parent attribute element value attribute element set attribute name attribute name return attribute element | generates an attribute element for the given name value pair |
public boolean is request throttle enabled return request throttle enabled get | returns true if request throttling is enabled |
private void generate property matchers element parent collection factory definition property matcher property matcher definitions for factory definition property matcher factory def property matcher definitions if factory def get inheritance inheritance inherited generate property matcher parent factory def | generates property matcher elements for the given collection of property matcher factory definitions |
public boolean enable request throttle boolean enable if enable is request throttle set throw new illegal state exception request throttle cannot be enabled since it has not been set for boolean currently enabled request throttle enabled get if enable currently enabled return false if request throttle enabled compare and set currently enabled enable return true | enables disables request throttling |
private element generate property matcher element parent factory definition property matcher factory def element property matcher element create element parent property matcher element property matcher element set attribute name attribute factory def get id generate def property matcher element factory def create text element property matcher element class name element factory def get factory class generate attributes property matcher element factory def get attributes return property matcher element | generate a property matche element for the given property matcher factory definition |
private void generate default property matcher element parent extendable string default property matcher id if default property matcher id null default property matcher id get inheritance inheritance inherited create text element parent default property matcher element default property matcher id to string | generates the default property matcher element |
public boolean has exceeded deviation threshold string node id list node nodes return get deviation node id nodes deviation threshold | determines whether or not the given node has exceeded the deviation threshold |
private void generate default availability policy element parent extendable string default availability policy definition id if default availability policy definition id null default availability policy definition id get inheritance inheritance inherited create text element parent default availability policy element default availability policy definition id to string | generates the default availability policy element |
private void generate availability policies element parent collection factory definition availability policy availability policy definitions for factory definition availability policy factory def availability policy definitions if factory def get inheritance inheritance inherited generate availability policy parent factory def | generates availability policy elements for the given collection of availability policy definition factories |
private element generate availability policy element parent factory definition availability policy factory def element availability policy element create element parent availability policy element availability policy element set attribute name attribute factory def get id generate def availability policy element factory def create text element availability policy element class name element factory def get factory class generate attributes availability policy element factory def get attributes return availability policy element | generates an availability policy element for the given availability policy definition factory |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.