This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.algorythms; | |
import java.util.Deque; | |
import java.util.LinkedList; | |
/** | |
* Created by dsemenov | |
* Date: 12/7/16. | |
*/ | |
public class FindNthInTree<D> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.alg.other | |
import java.util.concurrent.atomic.AtomicReference | |
/** | |
* Created by dsemenov | |
* Date: 1/28/16. | |
*/ | |
class Throttler(tps: Int) { | |
val maxInterval = tps / 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.alg.other | |
import org.sdo.alg.other.MaximumSumSubArray.Context | |
/** | |
* Created by dsemenov | |
* Date: 1/21/16. | |
*/ | |
object MaximumSumSubArray { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.alg.other | |
/** | |
* Created by dsemenov | |
* Date: 1/7/16. | |
*/ | |
trait WaterCollect { | |
def collectWater(towers: List[Int]): Int = { | |
def walkMax(towers: List[Int]): List[Int] = { | |
var tempMax = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql._ | |
import scala.concurrent.{ExecutionContext, Future} | |
import scala.util.{Failure, Success} | |
implicit val ec: ExecutionContext = ??? | |
val f1 = Future{ | |
val connection : Connection = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.alg.graph | |
case class TopoGraph(adjList: Map[String, List[String]]) { | |
var visited: Set[String] = Set() | |
var order: List[String] = Nil | |
def topologicalOrder(): List[String] = { | |
adjList foreach { | |
case (vertex, _) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.alg.geeks | |
/** | |
* Created by dsemenov | |
* Date: 1/5/16. | |
*/ | |
trait PossibleTrees[E] { | |
def findPossiblePreOrderTreesFor(inOrderTree: List[E]): List[List[E]] = inOrderTree match { | |
case Nil => Nil | |
case head :: Nil => List(List(head)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sdo.alg.geeks | |
/** | |
* Created by dsemenov | |
* Date: 12/30/15. | |
*/ | |
trait MajorityElement[E] { | |
private[this] def findCandidate(elements: List[E]): Option[E] = elements match { | |
case head :: tail => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void process(final AsyncProcessor processor, final Exchange exchange) throws Exception { | |
final AsyncProcessorAwaitManager awaitManager = exchange.getContext().getAsyncProcessorAwaitManager(); | |
final CountDownLatch latch = new CountDownLatch(1); | |
boolean sync = processor.process(exchange, new AsyncCallback() { | |
public void done(boolean doneSync) { | |
if (!doneSync) { | |
awaitManager.countDown(exchange, latch); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// write body | |
NettyHelper.writeBodyAsync(LOG, channel, remoteAddress, body, exchange, new ChannelFutureListener() { | |
public void operationComplete(ChannelFuture channelFuture) throws Exception { | |
LOG.trace("Operation complete {}", channelFuture); | |
if (!channelFuture.isSuccess()) { | |
// no success then exit, (any exception has been handled by ClientChannelHandler#exceptionCaught) | |
return; | |
} | |
// if we do not expect any reply then signal callback to continue routing |
NewerOlder