range

Data Structure for Storing Ranges

给你一囗甜甜゛ 提交于 2019-11-30 02:41:46
问题 I am wondering if anyone knows of a data structure which would efficiently handle the following situation: The data structure should store several, possibly overlapping, variable length ranges on some continuous timescale. For example, you might add the ranges a:[0,3], b:[4,7], c:[0,9] . Insertion time does not need to be particularly efficient. Retrievals would take a range as a parameter, and return all the ranges in the set that overlap with the range, for example: Get(1,2) would return a

How to generate normally distributed random from an integer range?

隐身守侯 提交于 2019-11-30 02:23:39
Given the start and the end of an integer range, how do I calculate a normally distributed random integer between this range? I realize that the normal distribution goes into -+ infinity. I guess the tails can be cutoff, so when a random gets computed outside the range, recompute. This elevates the probability of integers in the range, but as long as the this effect is tolerable (<5%), it's fine. public class Gaussian { private static bool uselast = true; private static double next_gaussian = 0.0; private static Random random = new Random(); public static double BoxMuller() { if (uselast) {

What are the ranges of coordinates in the CIELAB color space?

折月煮酒 提交于 2019-11-30 01:58:38
I have the following piece of code: public List<Tuple<double, double, double>> GetNormalizedPixels(Bitmap image) { System.Drawing.Imaging.BitmapData data = image.LockBits( new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat); int pixelSize = Image.GetPixelFormatSize(image.PixelFormat) / 8; var result = new List<Tuple<double, double, double>>(); unsafe { for (int y = 0; y < data.Height; ++y) { byte* row = (byte*)data.Scan0 + (y * data.Stride); for (int x = 0; x < data.Width; ++x) { Color c = Color.FromArgb( row[x * pixelSize + 3], row

Vim yanking range of lines

大城市里の小女人 提交于 2019-11-29 20:14:26
I'm a C# developer who has just recently decided to expand my knowledge of the tools available to me. The first tool I've decided to learn is Vi/Vim. Everything has been going well so far, but there are a couple of questions I can't seem to find the answer to: Lets say I wanted to yank a range of lines. I know there are many ways of doing so, but I would like to do it by line number. I figured it would be similar to how the substitute commands work, something like 81,91y . Is there a way to do this? I'm a little confused about the g command in normal mode. It seems to do a myriad of things and

Determining if a variable is within range?

人盡茶涼 提交于 2019-11-29 19:03:57
I need to write a loop that does something like: if i (1..10) do thing 1 elsif i (11..20) do thing 2 elsif i (21..30) do thing 3 etc... But so far have gone down the wrong paths in terms of syntax. if i.between?(1, 10) do thing 1 elsif i.between?(11,20) do thing 2 ... Use the === operator (or its synonym include? ) if (1..10) === i As @Baldu said, use the === operator or use case/when which internally uses === : case i when 1..10 # do thing 1 when 11..20 # do thing 2 when 21..30 # do thing 3 etc... if you still wanted to use ranges... def foo(x) if (1..10).include?(x) puts "1 to 10" elsif (11.

Doing a range lookup in C# - how to implement

天涯浪子 提交于 2019-11-29 18:00:01
I'm trying to understand how to implement the code found in thread by Jon Skeet: Doing a range lookup in C#? Can someone provide an setup example using something like: 1-10000, 10001-40000, 40000+ where is the first group returns a value of 1, 2, 3 respectively? I don't quite have a grasp of how that is done in this code. tx. public interface IRangeComparer<TRange, TValue> { /// <summary> /// Returns 0 if value is in the specified range; /// less than 0 if value is above the range; /// greater than 0 if value is below the range. /// </summary> int Compare(TRange range, TValue value); } ///

use a range as a dictionary key in Python, what option do I have?

穿精又带淫゛_ 提交于 2019-11-29 17:59:12
This is my first post and I'm quite new at programming, so I might not be able to convey my question appropriately, but I'll do my best! tries_dict = {1:'first', 2:'second', 3:'third', 4:'fourth', ub_tries:'last'} ub_tries = user input tries = 1 input ('\nCome on make your ' + tries_dict.get(tries) + guess: ') These 3 elements are part of a number guess game I created, and I included them in a while loop where tries += 1 after each wrong answer. As you can see, in my dictionary there are custom values for the first 4 answers and the last possible chance before the game is over, so here is what

How can fill I cells A1:A5 with a color using C#?

拟墨画扇 提交于 2019-11-29 16:52:18
I have the following code: Excel.Range chartRange; chartRange = xlWorkSheet.get_Range("A3", "R3"); I want to fill this range of cells with a color. I have already tried with: System.Drawing.Color = "yellow" but it is throwing an exception that an object reference is required. How can I fix my code to fill these cells with a color? Try this: chartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); The problem with your code shown above is that you can't assign the string value "Yellow" to the System.Drawing.Color type. Instead, the standard colors are

Matched Range Merge in R

梦想与她 提交于 2019-11-29 16:51:51
I would like to merge/combine two files, so that if an entry in column B of my first file falls into the range of columns B and C in my second file, the output will contain all of the information contained in both files. Like this: file 1 A B rs10 23353 rs100 10000 rs234 54440 file 2 A B C E235 20000 30000 E255 50000 60000 where, because 23353 falls between 20000 and 30000, and 54440 falls between 50000 and 60000 the output file would look like this: rs 23353 E235 20000 30000 rs234 54440 E255 50000 60000 and rs100 would be removed (from the output file) because it does not fall within a range

Slow highlighting in Firefox

你离开我真会死。 提交于 2019-11-29 15:53:04
We need to add anchors and highlights for some keywords/sentences in the html page. It turns out the highlighting is really slow in Firefox. In the following code, all ranges which need to be highlighted are stored in array hiliteRanges : for (var i = 0; i < hiliteRanges.length; i++){ document.designMode = "on"; var selHilites = window.getSelection(); if (selHilites.rangeCount > 0) selHilites.removeAllRanges(); selHilites.addRange(hiliteRanges[i]); var anchorId = 'index'+i; var insertedHTML = '<span id="' + anchorId + '" style="background-color: #FF8C00;" >'+hiliteRanges[i].toString()+'</span>