Permalink
Browse files

Merge branch 'devel' of github.com:triAGENS/AvocadoDB into devel

  • Loading branch information...
2 parents 3f8b284 + d9d34b0 commit f447245356309c32dbc210b68fdfcc595355dc0c @hkernbach hkernbach committed May 8, 2012
Showing with 2,428 additions and 1,920 deletions.
  1. +297 βˆ’226 Ahuacatl/ahuacatl-constant-folder.c
  2. +5 βˆ’5 Ahuacatl/ahuacatl-constant-folder.h
  3. +289 βˆ’0 BasicsC/json-utilities.c
  4. +89 βˆ’0 BasicsC/json-utilities.h
  5. +62 βˆ’0 BasicsC/vector.c
  6. +7 βˆ’0 BasicsC/vector.h
  7. +18 βˆ’0 Doxygen/Examples.AvocadoDB/api-simple-by-example1
  8. +15 βˆ’0 Doxygen/Examples.AvocadoDB/api-simple-by-example2
  9. +16 βˆ’0 Doxygen/Examples.AvocadoDB/api-simple-by-example3
  10. +11 βˆ’0 Doxygen/Examples.AvocadoDB/api-simple-first-example
  11. +12 βˆ’0 Doxygen/Examples.AvocadoDB/api-simple-first-example-not-found
  12. +6 βˆ’3 Doxygen/Examples.Durham/jsunity1
  13. +2 βˆ’0 Doxygen/Examples.Durham/shell-collection-count
  14. +2 βˆ’0 Doxygen/Examples.Durham/shell-simple-query-first-example
  15. +2 βˆ’2 Doxygen/Scripts/html2html.sh
  16. +3 βˆ’0 Makefile.files
  17. +109 βˆ’181 Makefile.in
  18. +1 βˆ’1 Makefile.local
  19. +1 βˆ’1 RestServer/api-index.dox
  20. +10 βˆ’1 RestServer/api-simple.dox
  21. +0 βˆ’3 RestServer/home.dox
  22. +3 βˆ’5 RestServer/install-manual.dox
  23. +64 βˆ’0 RestServer/module-jsunity.dox
  24. +9 βˆ’21 RestServer/otwp.dox
  25. +37 βˆ’19 RestServer/simple-queries.dox
  26. +21 βˆ’69 RestServer/user-manual-server.dox
  27. +10 βˆ’1 ShapedJson/json-shaper.c
  28. +1 βˆ’1 ShapedJson/json-shaper.h
  29. +25 βˆ’1 SkipLists/compare.h
  30. +14 βˆ’13 SkipLists/skiplist.c
  31. +3 βˆ’0 SkipLists/skiplistIndex.c
  32. +111 βˆ’8 UnitTests/HttpInterface/api-simple-spec.rb
  33. +8 βˆ’0 UnitTests/Philadelphia/vector-pointer-test.cpp
  34. +9 βˆ’1 V8/v8-vocbase.cpp
  35. +1 βˆ’1 VERSION
  36. +146 βˆ’215 aclocal.m4
  37. +14 βˆ’213 config/compile
  38. +178 βˆ’197 config/config.guess
  39. +68 βˆ’136 config/config.sub
  40. +56 βˆ’133 config/depcomp
  41. +14 βˆ’21 config/install-sh
  42. +97 βˆ’51 config/missing
  43. +199 βˆ’264 configure
  44. +1 βˆ’1 configure.ac
  45. +107 βˆ’23 js/actions/system/api-simple.js
  46. +60 βˆ’15 js/client/modules/simple-query.js
  47. +0 βˆ’31 js/common/modules/jsunity.js
  48. +17 βˆ’32 js/common/modules/simple-query-basics.js
  49. +125 βˆ’18 js/common/tests/shell-simple-query.js
  50. +5 βˆ’0 js/server/js-server.h
  51. +63 βˆ’7 js/server/modules/simple-query.js
  52. +5 βˆ’0 js/server/server.js

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -29,12 +29,13 @@
#define TRIAGENS_DURHAM_AHUACATL_CONSTANT_FOLDER_H 1
#include <BasicsC/common.h>
-#include <BasicsC/strings.h>
-#include <BasicsC/string-buffer.h>
+#include <BasicsC/associative.h>
#include <BasicsC/hashes.h>
+#include <BasicsC/json-utilities.h>
#include <BasicsC/logging.h>
+#include <BasicsC/strings.h>
+#include <BasicsC/string-buffer.h>
#include <BasicsC/vector.h>
-#include <BasicsC/associative.h>
#include "Ahuacatl/ahuacatl-ast-node.h"
#include "Ahuacatl/ahuacatl-tree-walker.h"
@@ -89,8 +90,7 @@ typedef struct TRI_aql_field_access_s {
char* _fieldName;
TRI_aql_access_e _type;
union {
- TRI_json_t* _exactValue;
- TRI_json_t* _list;
+ TRI_json_t* _value;
TRI_aql_range_t _singleRange;
struct {
TRI_aql_range_t _lower;
View
@@ -0,0 +1,289 @@
+////////////////////////////////////////////////////////////////////////////////
+/// @brief utility functions for json objects
+///
+/// @file
+///
+/// DISCLAIMER
+///
+/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+/// Copyright holder is triAGENS GmbH, Cologne, Germany
+///
+/// @author Jan Steemann
+/// @author Copyright 2012, triagens GmbH, Cologne, Germany
+////////////////////////////////////////////////////////////////////////////////
+
+#include <BasicsC/json-utilities.h>
+
+// -----------------------------------------------------------------------------
+// --SECTION-- private functions
+// -----------------------------------------------------------------------------
+
+////////////////////////////////////////////////////////////////////////////////
+/// @addtogroup Json
+/// @{
+////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief fruitsort initialisation parameters
+///
+/// Included fsrt.inc with these parameters will create a function SortJsonList
+/// that is used to do the sorting. SortJsonList will call OrderDataCompareFunc()
+/// to do the actual element comparisons
+////////////////////////////////////////////////////////////////////////////////
+
+static int CompareJson (TRI_json_t*, TRI_json_t*, size_t);
+
+#define FSRT_INSTANCE SortJson
+#define FSRT_NAME SortListJson
+#define FSRT_TYPE TRI_json_t
+#define FSRT_COMP(l,r,s) CompareJson(l,r,s)
+
+uint32_t SortJsonFSRT_Rand = 0;
+static uint32_t SortJsonRandomGenerator (void) {
+ return (SortJsonFSRT_Rand = SortJsonFSRT_Rand * 31415 + 27818);
+}
+#define FSRT__RAND \
+ ((fs_b) + FSRT__UNIT * (SortJsonRandomGenerator() % FSRT__DIST(fs_e,fs_b,FSRT__SIZE)))
+
+#include <BasicsC/fsrt.inc>
+
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief get type weight of a json value usable for comparison and sorting
+////////////////////////////////////////////////////////////////////////////////
+
+static inline int TypeWeight (const TRI_json_t* const value) {
+ switch (value->_type) {
+ case TRI_JSON_BOOLEAN:
+ return 1;
+ case TRI_JSON_NUMBER:
+ return 2;
+ case TRI_JSON_STRING:
+ return 3;
+ case TRI_JSON_LIST:
+ return 4;
+ case TRI_JSON_ARRAY:
+ return 5;
+ case TRI_JSON_NULL:
+ case TRI_JSON_UNUSED:
+ default:
+ return 0;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief callback function used for json value sorting
+////////////////////////////////////////////////////////////////////////////////
+
+static int CompareJson (TRI_json_t* lhs, TRI_json_t* rhs, size_t size) {
+ return TRI_CompareValuesJson((TRI_json_t*) lhs, (TRI_json_t*) rhs);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @}
+////////////////////////////////////////////////////////////////////////////////
+
+// -----------------------------------------------------------------------------
+// --SECTION-- public functions
+// -----------------------------------------------------------------------------
+
+////////////////////////////////////////////////////////////////////////////////
+/// @addtogroup Json
+/// @{
+////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief compare two json values
+////////////////////////////////////////////////////////////////////////////////
+
+int TRI_CompareValuesJson (const TRI_json_t* const lhs,
+ const TRI_json_t* const rhs) {
+ int lWeight = TypeWeight(lhs);
+ int rWeight = TypeWeight(rhs);
+
+ if (lWeight < rWeight) {
+ return -1;
+ }
+
+ if (lWeight > rWeight) {
+ return 1;
+ }
+
+ // equal weight
+ switch (lhs->_type) {
+ case TRI_JSON_UNUSED:
+ case TRI_JSON_NULL:
+ return 0; // null == null;
+
+ case TRI_JSON_BOOLEAN:
+ if (lhs->_value._boolean == rhs->_value._boolean) {
+ return 0;
+ }
+
+ if (!lhs->_value._boolean && rhs->_value._boolean) {
+ return -1;
+ }
+
+ return 1;
+
+ case TRI_JSON_NUMBER:
+ if (lhs->_value._number == rhs->_value._number) {
+ return 0;
+ }
+
+ if (lhs->_value._number < rhs->_value._number) {
+ return -1;
+ }
+
+ return 1;
+
+ case TRI_JSON_STRING:
+ return strcmp(lhs->_value._string.data, rhs->_value._string.data);
+
+ case TRI_JSON_LIST: {
+ size_t nl = lhs->_value._objects._length;
+ size_t nr = rhs->_value._objects._length;
+ size_t i;
+
+ for (i = 0; i < nl; ++i) {
+ int result;
+
+ if (i >= nr) {
+ // left list is longer
+ return 1;
+ }
+
+ result = TRI_CompareValuesJson(TRI_AtVector(&lhs->_value._objects, i),
+ TRI_AtVector(&rhs->_value._objects, i));
+ if (result != 0) {
+ return result;
+ }
+ }
+
+ // right list is longer
+ if (nr > nl) {
+ return -1;
+ }
+
+ return 0;
+ }
+
+ case TRI_JSON_ARRAY: {
+ size_t nl = lhs->_value._objects._length;
+ size_t nr = rhs->_value._objects._length;
+ size_t i;
+
+ for (i = 0; i < nl; i += 2) {
+ int result;
+
+ if (i > nr) {
+ // left list is longer
+ return 1;
+ }
+
+ // compare key
+ result = TRI_CompareValuesJson(TRI_AtVector(&lhs->_value._objects, i),
+ TRI_AtVector(&rhs->_value._objects, i));
+ if (result != 0) {
+ return result;
+ }
+
+ // compare value
+ result = TRI_CompareValuesJson(TRI_AtVector(&lhs->_value._objects, i + 1),
+ TRI_AtVector(&rhs->_value._objects, i + 1));
+ if (result != 0) {
+ return result;
+ }
+ }
+
+ // right list is longer
+ if (nr > nl) {
+ return -1;
+ }
+
+ return 0;
+ }
+
+ default:
+ return 0;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief check if two json values are the same
+////////////////////////////////////////////////////////////////////////////////
+
+bool TRI_CheckSameValueJson (const TRI_json_t* const lhs,
+ const TRI_json_t* const rhs) {
+ return (TRI_CompareValuesJson(lhs, rhs) == 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief checks if a json value is contained in a json list
+////////////////////////////////////////////////////////////////////////////////
+
+bool TRI_CheckInListJson (const TRI_json_t* const search,
+ const TRI_json_t* const list) {
+ size_t n;
+ size_t i;
+
+ assert(search);
+ assert(list);
+ assert(list->_type == TRI_JSON_LIST);
+
+ // iterate over list
+ n = list->_value._objects._length;
+ for (i = 0; i < n; ++i) {
+ TRI_json_t* listValue = (TRI_json_t*) TRI_AtVector(&list->_value._objects, i);
+
+ if (TRI_CheckSameValueJson(search, listValue)) {
+ // value is contained in list, exit
+ return true;
+ }
+ }
+
+ // finished list iteration, value not contained
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @brief sorts a json list in place
+////////////////////////////////////////////////////////////////////////////////
+
+TRI_json_t* TRI_SortListJson (TRI_json_t* const list) {
+ size_t n;
+
+ assert(list);
+ assert(list->_type == TRI_JSON_LIST);
+
+ n = list->_value._objects._length;
+ if (n > 1) {
+ // only sort if more than one value in list
+ SortListJson((TRI_json_t*) TRI_BeginVector(&list->_value._objects),
+ (TRI_json_t*) TRI_EndVector(&list->_value._objects));
+ }
+
+ return list;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// @}
+////////////////////////////////////////////////////////////////////////////////
+
+// Local Variables:
+// mode: outline-minor
+// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
+// End:
Oops, something went wrong.

0 comments on commit f447245

Please sign in to comment.