Why the compiler emits box instructions to compare instances of a reference type?

It’s required to satisfy the verifiability constraints for the generated IL. Note that unverifiable doesn’t necessarily mean incorrect. It works just fine without the box instruction as long as its security context allows running unverifiable code. Verification is conservative and is based on a fixed rule set (like reachability). To simplify things, they chose not … Read more

EqualityComparer.Default vs. T.Equals

It should be the same, but it is not guaranteed, because it depends on implementation details of the type T. Explanation: Without a constraint to T, o1.Equals(o2) will call Object.Equals, even if T implements IEquatable<T>. EqualityComparer<T>.Default however, will use Object.Equals only, if T doesn’t implement IEquatable<T>. If it does implement that interface, it uses IEquatable<T>.Equals. … Read more

How to find out if letter is Alphanumeric or Digit in Swift

For Swift 5 see rustylepord’s answer. Update for Swift 3: let letters = CharacterSet.letters let digits = CharacterSet.decimalDigits var letterCount = 0 var digitCount = 0 for uni in phrase.unicodeScalars { if letters.contains(uni) { letterCount += 1 } else if digits.contains(uni) { digitCount += 1 } } (Previous answer for older Swift versions) A possible … Read more

Text comparison algorithm

Typically this is accomplished by finding the Longest Common Subsequence (commonly called the LCS problem). This is how tools like diff work. Of course, diff is a line-oriented tool, and it sounds like your needs are somewhat different. However, I’m assuming that you’ve already constructed some way to compare words and sentences.

Is it valid to compare a double with an int in java?

Yes, it’s valid – it will promote the int to a double before performing the comparison. See JLS section 15.20.1 (Numerical Comparison Operators) which links to JLS section 5.6.2 (Binary Numeric Promotion). From the latter: Widening primitive conversion (ยง5.1.2) is applied to convert either or both operands as specified by the following rules: If either … Read more

Why are tuples constructed from differently initialized sets equal?

At first glance, it appears that x should always equal y, because two sets constructed from the same elements are always equal: >>> x = set([1, “a”, “b”, “c”, “z”, “f”]) >>> y = set([“a”, “b”, “c”, “z”, “f”, 1]) >>> x {1, ‘z’, ‘a’, ‘b’, ‘c’, ‘f’} >>> y {1, ‘z’, ‘a’, ‘b’, ‘c’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)