Exemple #1
0
/* compute the logarithm of the KT-estimator update multiplier */
double CTNode::logKTMul(bit_t b) const {

    static const double alpha = 0.5;
    static const double alpha2 = 2.0 * alpha;

    double kt_mul_numer = double(m_count[b]) + alpha;
    double kt_mul_denom = double(visits()) + alpha2;

    return std::log(kt_mul_numer / kt_mul_denom);
}
NS_IMETHODIMP
PlaceInfo::GetVisits(JSContext* aContext,
                     JS::Value* _visits)
{
  // If the visits data was not provided, return null rather
  // than an empty array to distinguish this case from the case
  // of a place without any visit.
  if (!mVisitsAvailable) {
    *_visits = JSVAL_NULL;
    return NS_OK;
  }

  // TODO bug 625913 when we use this in situations that have more than one
  // visit here, we will likely want to make this cache the value.
  JS::Rooted<JSObject*> visits(aContext,
                               JS_NewArrayObject(aContext, 0, nullptr));
  NS_ENSURE_TRUE(visits, NS_ERROR_OUT_OF_MEMORY);

  JS::Rooted<JSObject*> global(aContext, JS::CurrentGlobalOrNull(aContext));
  NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();

  for (VisitsArray::size_type idx = 0; idx < mVisits.Length(); idx++) {
    nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
    nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
                                  NS_GET_IID(mozIVisitInfo),
                                  getter_AddRefs(wrapper));
    NS_ENSURE_SUCCESS(rv, rv);

    JS::Rooted<JSObject*> jsobj(aContext, wrapper->GetJSObject());
    NS_ENSURE_STATE(jsobj);
    JS::Rooted<JS::Value> wrappedVisit(aContext, OBJECT_TO_JSVAL(jsobj));

    bool rc = JS_SetElement(aContext, visits, idx, &wrappedVisit);
    NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
  }

  *_visits = OBJECT_TO_JSVAL(visits);

  return NS_OK;
}